A lazily parsed JSON virtual tree library for Java.
Virtual here means it represents the "wanted" or "expected" tree structure. On leaf value access it is checked against the actual tree structure underneath, so navigation is painless and checks only happen when values are resolved (extracted) from the actual tree.
Lazily parsed means only the parts of the underlying tree that are used during navigation get parsed into nodes which remember offsets ("pointers") into the original JSON input. Untouched parts are skipped over until they are used. This makes for a fast, memory-efficient implementation that is convenient to query and can be extended with user types, handling inputs in the MB range without problems.
// parsing JSON text
JsonArray numbers = JsonMixed.of("[1,2,3]");
int v1 = numbers.get(1).intValue(); // = 2
int[] values = numbers.intValues().toArray(); // = [1,2,3]
// programmatic Java => JSON
JsonString s = Json.of( "hello" ); // note: no quotes
JsonInteger i = Json.of( 42 );
// programmatic dynamic composition Java => JSON
JsonObject root = Json.object( obj ->
obj.addNumber( "x", 1 ).addNumber( "y", 5 ) );
root.toJson(); // {"x":1,"y":5}Learn
- Getting started — install and first example
- Lazy parsing and the virtual tree — the idea behind the library
- Java API — build a tree from Java types
- JSON API — work from a JSON document
- Null, undefined and existence — the subtle states
- User types as JSON tree — extend the tree with your own types
Discover
- Navigating the tree — paths as a uniform way to drill down.
- Querying the tree — finding nodes using matchers.
- Validation — check input against a target schema
- Equivalence and identity — comparing two trees for sameness.
- Comparing JSON values (diff) — structural comparison
- Modification — bulk patching JSON using patch operations
- Mask & Overlay — masking JSON or patch merge with another JSON value
Overviews
- API reference — types and methods at a glance
- Standards and RFCs — conformance and deviations
Specifications
- JSON5* notation — the JSON5 variant accepted by the parser.
- JURL notation — JURL = JSON in the URL; a notation to encode JSON data in URL parameters
- Input Expressions — a RegEx alternative that is simple, safe and fast
Coordinates:
<dependency>
<groupId>org.hisp.dhis</groupId>
<artifactId>json-tree</artifactId>
<version>1.12.0</version>
</dependency>