Expand description
JSON query language interpreter.
This crate allows you to execute jq-like filters.
The example below demonstrates how to use this crate.
See the implementation in the jaq
crate if you are interested in how to:
- enable usage of the standard library,
- load JSON files lazily,
- handle errors etc.
(This example requires enabling the serde_json
feature for jaq-json
.)
use jaq_core::{load, Compiler, Ctx, Error, FilterT, RcIter};
use jaq_json::Val;
use serde_json::{json, Value};
let input = json!(["Hello", "world"]);
let program = File { code: ".[]", path: () };
use load::{Arena, File, Loader};
let loader = Loader::new(jaq_std::defs().chain(jaq_json::defs()));
let arena = Arena::default();
// parse the filter
let modules = loader.load(&arena, program).unwrap();
// compile the filter
let filter = jaq_core::Compiler::default()
.with_funs(jaq_std::funs().chain(jaq_json::funs()))
.compile(modules)
.unwrap();
let inputs = RcIter::new(core::iter::empty());
// iterator over the output values
let mut out = filter.run((Ctx::new([], &inputs), Val::from(input)));
assert_eq!(out.next(), Some(Ok(Val::from(json!("Hello")))));;
assert_eq!(out.next(), Some(Ok(Val::from(json!("world")))));;
assert_eq!(out.next(), None);;
Re-exports§
Modules§
- box_
iter - Boxed iterators.
- compile
- Program compilation.
- load
- Combined file loading, lexing, and parsing for multiple modules.
- ops
- Binary operations.
- path
- Paths and their parts.
- val
- Values that can be processed by jaq.
Structs§
- Ctx
- Filter execution context.
- Error
- Error that occurred during filter execution.
- Exn
- Exception.
- Filter
- Function from a value to a stream of value results.
- Native
- A filter which is implemented using function pointers.
- RcIter
- A more flexible version of
&mut impl Iterator
.
Enums§
- Bind
- Argument of a definition, such as
$v
orf
indef foo($v; f): ...
.
Traits§
- FilterT
- Function from a value to a stream of value results.