A small, embeddable JSON query engine for Java, built on Gson and designed for high‑throughput systems such as MAPS Messaging.
This implementation is inspired by jsonquerylang, but is intentionally constrained:
- No mutation
- No scripting
- No runtime eval
- Compile once, execute many
Filtering is powered by MAPS’ JMS selector parser, giving you a proven predicate language instead of inventing yet another one.
- Gson‑native (
JsonElementeverywhere) - Compile JSON query ASTs into executable functions
- Stable sorting
- Selector‑based filtering (JMS selectors)
- Deterministic, side‑effect‑free execution
- Pluggable function registry
Supported functions:
getfiltersortmappickpipe
JsonQueryCompiler compiler = JsonQueryCompiler.createDefault();JsonElement query = JsonParser.parseString("""
["pipe",
["filter", "address.state = 'Alaska'"],
["sort", ["get","age"], "desc"],
["pick", "first", "age"]
]
""");
Function<JsonElement, JsonElement> program = compiler.compile(query);JsonElement input = JsonParser.parseString("""
[
{"first":"Chris","age":23,"address":{"state":"Alaska"}},
{"first":"Joe","age":32,"address":{"state":"Alaska"}},
{"first":"Emily","age":19,"address":{"state":"Texas"}}
]
""");
JsonElement result = program.apply(input);Queries are expressed as JSON ASTs, not strings.
["get", "age"]["filter", "address.state = 'Alaska'"]["sort", ["get","age"], "desc"]["map", ["get","age"]]["pick", "name", "age"]["pipe",
["filter", "state = 'Alaska'"],
["sort", ["get","age"], "desc"],
["pick", "name", "age"]
]Filtering uses the MAPS JMS selector parser, so predicates like these are supported:
state = 'Alaska'
age >= 21
address.state IN ('Alaska','Texas')
Selectors are compiled once and evaluated per element.
Add your own functions without touching the compiler:
Map<String, JsonQueryFunction> custom = new HashMap<>();
custom.put("myFn", new MyFunction());
JsonQueryCompiler compiler =
JsonQueryCompiler.create(FunctionRegistry.builtIns(),
new FunctionRegistry(custom));Each function lives in its own class and implements:
JsonQueryFunction- Predictable execution
- Explicit null handling
- Zero reflection
- No hidden magic
- Broker‑safe performance characteristics
This is a query/filter engine, not a programming language.
Apache License 2.0 with Commons Clause
See LICENSE for details.