Module json_values

Class JsReader

java.lang.Object
jsonvalues.spec.JsReader

public final class JsReader extends Object
Object for processing JSON from byte[] and InputStream. The only public methods are readNextToken() and reset(). Most of the time you don't need to parse a JSON token by token since there are a lot of high-level and efficient alternatives implemented in json-values. Just in case, find below an example:
     
            String json = "[1,2,3]";
            var reader = JsonIO.INSTANCE.createReader(json.getBytes(StandardCharsets.UTF_8));
            byte token;
            while ((token = reader.readNextToken()) != ']'){
                if(Character.isDigit(token)) System.out.println(Character.toString(token));
            }


     

 

You can also read tokens as JsValue and validate them using the method JsSpec.readNextValue(JsReader)

  • Method Details

    • reset

      public void reset()
      Reset reader after processing input It will release reference to provided byte[] or InputStream input
    • readNextToken

      public byte readNextToken() throws JsParserException
      Read next token (byte) from input JSON. Whitespace will be skipped and next non-whitespace byte will be returned.
      Returns:
      next non-whitespace byte in the JSON input
      Throws:
      JsParserException - unable to get next byte (end of stream, ...)