Class JSONParser

java.lang.Object
nonapi.io.github.classgraph.types.Parser
nonapi.io.github.classgraph.json.JSONParser

final class JSONParser extends Parser
A JSON parser, based on the PEG grammar found at: https://github.com/azatoth/PanPG/blob/master/grammars/JSON.peg
  • Constructor Details

  • Method Details

    • getAndParseHexChar

      private int getAndParseHexChar() throws ParseException
      Get and parse a hexadecimal digit character.
      Returns:
      the hex char
      Throws:
      ParseException - if the character was not hexadecimal
    • parseString

      private CharSequence parseString() throws ParseException
      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

      private Number parseNumber() throws ParseException
      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

      private JSONArray parseJSONArray() throws ParseException
       
           Array ← "[" ( JSON ( "," JSON )* / S? ) "]"
       
       
      .
      Returns:
      the JSON array
      Throws:
      ParseException - if parsing fails
    • parseJSONObject

      private JSONObject parseJSONObject() throws ParseException
      Parse a JSON Object.
       
           Object ← "{" ( String ":" JSON ( "," String ":" JSON )* / S? ) "}"
       
       
      Returns:
      the JSON object
      Throws:
      ParseException - if parsing fails
    • parseJSON

      private Object parseJSON() throws ParseException
      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

      static Object parseJSON(String str) throws ParseException
      Parse a JSON object, array, string, value or object reference.
      Parameters:
      str - the str
      Returns:
      the parsed JSON object
      Throws:
      ParseException - if parsing fails