Module json5

Class JSONParser


  • public class JSONParser
    extends Object
    A JSONParser is used to convert a source string into tokens, which then are used to construct JSONObjects and JSONArrays
    Author:
    SyntaxError404
    • Field Detail

      • root

        protected boolean root
        whether we're currently parsing the root object/array
    • Constructor Detail

      • JSONParser

        public JSONParser​(Reader reader,
                          JSONOptions options)
        Constructs a new JSONParser from a Reader. The reader is not closed
        Parameters:
        reader - a reader
        options - the options for parsing
        Since:
        1.1.0
      • JSONParser

        public JSONParser​(String source,
                          JSONOptions options)
        Constructs a new JSONParser from a string
        Parameters:
        source - a string
        options - the options for parsing
        Since:
        1.1.0
      • JSONParser

        public JSONParser​(InputStream stream,
                          JSONOptions options)
        Constructs a new JSONParser from an InputStream. The stream is not closed
        Parameters:
        stream - a stream
        options - the options for parsing
        Since:
        1.1.0
      • JSONParser

        public JSONParser​(Reader reader)
        Constructs a new JSONParser from a Reader. The reader is not closed. This uses the default options
        Parameters:
        reader - a reader
      • JSONParser

        public JSONParser​(String source)
        Constructs a new JSONParser from a string. This uses the default options
        Parameters:
        source - a string
      • JSONParser

        public JSONParser​(InputStream stream)
        Constructs a new JSONParser from an InputStream. The stream is not closed. This uses the default options
        Parameters:
        stream - a stream
    • Method Detail

      • back

        public void back()
        Forces the parser to re-read the last character
      • nextClean

        public char nextClean()
        Reads until encountering a character that is not a whitespace according to the JSON5 Specification
        Returns:
        a non-whitespace character, or 0 if the end of the stream has been reached
      • nextMemberName

        public String nextMemberName()
        Reads a member name from the source according to the JSON5 Specification
        Returns:
        an member name
      • syntaxError

        public JSONException syntaxError​(String message,
                                         Throwable cause)
        Constructs a new JSONException with a detail message and a causing exception
        Parameters:
        message - the detail message
        cause - the causing exception
        Returns:
        a JSONException
      • syntaxError

        public JSONException syntaxError​(String message)
        Constructs a new JSONException with a detail message
        Parameters:
        message - the detail message
        Returns:
        a JSONException
      • charToString

        protected static String charToString​(char c)
        Converts a character into a string representation:
        • if c == 0, "EOF" is returned
        • if c fulfills one of the following conditions, "'x'" is returned, where x is the value returned by Character.toString(char):
        • otherwise, "U+XXXX" is returned, where XXXX is the uppercase hexadecimal representation of c's Unicode codepoint, padded with zeros (0) to a length of 4 characters
        Parameters:
        c - the character
        Returns:
        the string representation
        Since:
        2.1.0