The crate jqlite is the Rust port of jqlite, a portable profile of the jq language. It is a file-by-file port of the .NET reference engine: it follows the same specification and passes the same conformance corpus (spec/tests), so a program gives the same results here as in every other implementation.
You parse a jq program once into a JqExpression, then evaluate it on JqValue inputs, from as many threads as you like.
regex and stacker. The crate has no unsafe code and no build script.The crate is jqlite on crates.io:
[dependencies]
jqlite = "1"
To follow the repository instead, use a path dependency on the rust folder of a clone:
[dependencies]
jqlite = { path = "../jqlite/rust" }
use jqlite::{JqError, JqValue};
fn main() -> Result<(), JqError> {
let input = JqValue::parse(r#"{"users":[{"name":"Ada","age":36},{"name":"Linus","age":28}]}"#)?;
for result in jqlite::evaluate(".users[] | select(.age > 30) | .name", input)? {
println!("{result}");
}
Ok(())
}
"Ada"
JqValue::parse reads one JSON value. jqlite::evaluate parses the program and runs it on that input, returning every output in a Vec<JqValue>. A JqValue prints as compact JSON with {} (Display) or with to_json().
To run a program on many inputs, parse it once and keep the expression:
let names = jqlite::parse(".users[] | .name")?;
let results = names.evaluate(input)?;
| Page | What it covers |
|---|---|
| Evaluating | One-shot evaluation, parse once and evaluate many times, streaming results, threads |
| Values | JqValue: building inputs, reading results, numbers, strings, key order, ownership |
| Variables | Passing $name variables to an evaluation |
| Options | JqOptions: $ENV, the clock and time zone, the depth limit, debug and stderr |
| Modules | import, include, data modules, modulemeta, resolvers |
| Errors | JqError: parse, run-time, halt_error, invalid arguments |
| JSON Lines | Running a program on each value of a JSON Lines file |
| API reference | Every public item of the crate |
| The port | Building, testing and the differences from the .NET reference |
The language itself is described in the language guide; what jqlite changes from jq 1.8 is in the spec, §13.