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}- 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
- Validation — check input against a target schema
- Comparing JSON values (diff) — structural comparison
- API reference — types and methods at a glance
- Standards and RFCs — conformance and deviations
Coordinates:
<dependency>
<groupId>org.hisp.dhis</groupId>
<artifactId>json-tree</artifactId>
<version>1.12.0</version>
</dependency>