Class JSONParser
java.lang.Object
nonapi.io.github.classgraph.types.Parser
nonapi.io.github.classgraph.json.JSONParser
A JSON parser, based on the PEG grammar found at:
https://github.com/azatoth/PanPG/blob/master/grammars/JSON.peg
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate intGet and parse a hexadecimal digit character.private ObjectParse a JSON type (object / array / value).(package private) static ObjectParse a JSON object, array, string, value or object reference.private JSONArrayArray ← "[" ( JSON ( "," JSON )* / S? ) "]"private JSONObjectParse a JSON Object.private NumberParses and returns Integer, Long or Double type.private CharSequenceParse a quoted/escaped JSON string.Methods inherited from class Parser
advance, appendToToken, appendToToken, currToken, expect, getc, getPosition, getPositionInfo, getState, getSubsequence, getSubstring, hasMore, next, peek, peekExpect, peekMatches, setPosition, setState, skipWhitespace, toString
-
Constructor Details
-
JSONParser
Constructor.- Parameters:
string- the string- Throws:
ParseException- if parsing fails
-
-
Method Details
-
getAndParseHexChar
Get and parse a hexadecimal digit character.- Returns:
- the hex char
- Throws:
ParseException- if the character was not hexadecimal
-
parseString
Parse a quoted/escaped JSON string.String ← S? ["] ( [^ " \ U+0000-U+001F ] / Escape )* ["] S? Escape ← [\] ( [ " / \ b f n r t ] / UnicodeEscape ) UnicodeEscape ← "u" [0-9A-Fa-f]{4}- Returns:
- the char sequence
- Throws:
ParseException- if the escape sequence was invalid
-
parseNumber
Parses and returns Integer, Long or Double type.Number ← Minus? IntegralPart FractionalPart? ExponentPart? Minus ← "-" IntegralPart ← "0" / [1-9] [0-9]* FractionalPart ← "." [0-9]+ ExponentPart ← ( "e" / "E" ) ( "+" / "-" )? [0-9]+- Returns:
- the number
- Throws:
ParseException- if parsing fails
-
parseJSONArray
Array ← "[" ( JSON ( "," JSON )* / S? ) "]".- Returns:
- the JSON array
- Throws:
ParseException- if parsing fails
-
parseJSONObject
Parse a JSON Object.Object ← "{" ( String ":" JSON ( "," String ":" JSON )* / S? ) "}"- Returns:
- the JSON object
- Throws:
ParseException- if parsing fails
-
parseJSON
Parse a JSON type (object / array / value).String values will have CharSequence type. Numerical values will have Integer, Long or Double type. Can return null for JSON null value.
JSON ← S? ( Object / Array / String / True / False / Null / Number ) S?- Returns:
- the parsed JSON object
- Throws:
ParseException- if parsing fails
-
parseJSON
Parse a JSON object, array, string, value or object reference.- Parameters:
str- the str- Returns:
- the parsed JSON object
- Throws:
ParseException- if parsing fails
-