JParse is a small, fast, and compliant JSON parser that implements events parsing and index overlay.
Fastest, most compliant and smallest JSON parser lib for the JVM, and it is developer friendly.
Apache 2.
JParse is an innovative JSON parser for JVM that offers lightning-fast parsing speeds through an index overlay mechanism. JParse is the most efficient, fastest, and developer-friendly JSON parser available for the JVM. This makes it ideal for processing massive data sets, building complex data pipelines or simply for a faster and more efficient way to parse JSON data.
JParse is a JSON parser plus a small subset of JSONPath.
This is a short guide on how to use JParse. (Go to the wiki for a longer guide on how to use JParse.)
JParse has no dependencies except the JVM itself.
<!-- See for latest version https://mvnrepository.com/artifact/io.nats/jparse -->
<dependency>
<groupId>io.nats</groupId>
<artifactId>jparse</artifactId>
<version>1.2.0</version>
</dependency>
//See for latest version https://mvnrepository.com/artifact/io.nats/jparse
implementation group: 'io.nats', name: 'jparse', version: '1.2.3'
final File file = new File("./src/test/resources/json/depts.json");
final var rootNode = Json.toRootNode(Sources.fileSource(file));
Extract employees from the engineering department:
final var engineeringEmployees = Path.atPath("departments[0].employees", rootNode).asCollection().asArray();
Extract specific node from the engineeringEmployees array:
final var cindy = Path.atPath("[2]", engineeringEmployees);
Extract different parts of the cindy node:
final var cindyName = Path.atPath("[2].firstName", engineeringEmployees);
final var cindyId = Path.atPath(".id", cindy);
final var manager = Path.atPath("[2].manager", engineeringEmployees);
JParse uses standard Java types, making it straightforward to use with no surprises:
JSON Type | Java Type |
---|---|
JSON number | java.lang.Number |
JSON array | java.util.List |
JSON array | Java array (e.g., int[]) |
JSON String and every node | java.lang.CharSequence |
JSON object | java.util.Map |
JParse supports Java streams and functional programming:
final var rick = engineeringEmployees.stream()
.map(node -> node.asCollection().asObject())
.filter(objectNode -> objectNode.getString("firstName").equals("Rick"))
.findFirst();
You can also use JParse for functional mapping and find operations:
final var rick2 = engineeringEmployees.findObjectNode(
objectNode -> objectNode.getString("firstName").equals("Rick")
);
JParse supports easy object mappings:
public record Employee(String firstName, String lastName,
String dob, boolean manager,
int id, int managerId) {
}
final var employees = engineeringEmployees.mapObjectNode(on ->
new Employee(on.getString("firstName"), on.getString("lastName"),
on.getString("dob"), on.getBoolean("manager"),
on.getInt("id"), on.getInt("managerId"))
);