Package groovy.json

Class JsonLexer

  • All Implemented Interfaces:
    Iterator<JsonToken>

    public class JsonLexer
    extends Object
    implements Iterator<JsonToken>
    The lexer reads JSON tokens in a streaming fashion from the underlying reader.
    Since:
    1.8.0
    • Constructor Detail

      • JsonLexer

        public JsonLexer​(Reader reader)
        Instantiates a lexer with a reader from which to read JSON tokens. Under the hood, the reader is wrapped in a LineColumnReader, for line and column information, unless it's already an instance of that class.
        Parameters:
        reader - underlying reader
    • Method Detail

      • getReader

        public LineColumnReader getReader()
        Underlying reader from which to read the JSON tokens. This reader is an instance of LineColumnReader, to keep track of line and column positions.
      • nextToken

        public JsonToken nextToken()
        Returns:
        the next token from the stream
      • unescape

        public static String unescape​(String input)
        Replace unicode escape and other control characters with real characters
        Parameters:
        input - text
        Returns:
        input text without the escaping
      • skipWhitespace

        public int skipWhitespace()
        Skips all the whitespace characters and moves the cursor to the next non-space character.
      • hasNext

        public boolean hasNext()
        Iterator method to know if another token follows, or if we've reached the end of the stream.
        Specified by:
        hasNext in interface Iterator<JsonToken>
        Returns:
        true if there are more tokens
      • next

        public JsonToken next()
        Iterator method to get the next token of the stream.
        Specified by:
        next in interface Iterator<JsonToken>
        Returns:
        the next token