The OpenJAX JSON library provides JsonReader
and JsonParser
.
The JsonReader
is a subclass of Reader
that reads JSON documents and validates the content conforms to the RFC 4627 specification. In addition to the standard "read" methods defined in Reader
, the JsonReader
provides the following patterns:
- Standard reading of "JSON tokens":
- Via
JsonReader#readToken()
, which returns tokens asString
s.
- Via
- Iterator reading of "JSON tokens". The
JsonReader
implements theIterable
interface:- Via
Iterator#next()
, which returns tokens asString
s.
- Via
- Optimized reading of "JSON tokens":
JsonReader#readTokenStart()
, which returns the start index of the token.
- Partial reading of "JSON tokens":
- Via:
Reader#read()
. - Via:
Reader#read(char[])
. - Via:
Reader#read(char[], int, int)
.
- Via:
- The
JsonReader
is aReplayReader
, which allows a JSON document to be re-read:- Via:
JsonReader#setPosition(int)
: The character position to be reset to previous point in the stream being read. - Via:
JsonReader#setIndex(int)
: The token index position to be reset to a previous point of enumerated "JSON tokens".
- Via:
- Ignore or preserve inter-token whitespace.
- Unescapes string-literal JSON escape codes as defined in RFC 4627, Section 2.5.
The JsonParser
is a validating parser for JSON documents that asserts content conforms to the RFC 4627 specification. The JsonParser
is designed with performance in mind, and utilizes the JsonReader#readTokenStart()
method to avoid instantiation of String
object. The JsonParser
accepts a JsonHandler
that defines methods for the reconstitution of "JSON tokens" from the provided _start and end token indices.
JSON Tokens | |
---|---|
Structural | |
A character that is one of: | [{}\[\]:,] |
A property key | |
A string that matches: | ^".*"$ |
A property or array member value | |
A string that matches: | ^".*"$ |
A number that matches: | ^-?(([0-9])|([1-9][0-9]+))(\.[\.0-9]+)? ([eE][+-]?(([0-9])|([1-9][0-9]+)))?$ |
A literal that matches: | ^(null)|(true)|(false)$ |
Whitespace | |
Whitespace string that matches: | ^[ \n\r\t]+$ |
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
This project is licensed under the MIT License - see the LICENSE.txt file for details.