Expand description
Compile & run jq filters and read & write data.
This crate provides an opinionated, high-level API to integrate jaq into applications. It combines the functionality of several crates, which it re-exports:
jaq-core: basic compilation/execution of jq filtersjaq-std: standard libraryjaq-json: type of valuesjaq-fmts: multi-format support
In contrast to these crates, which aim for minimal functionality and maximal flexibility, this crate aims for maximal functionality and minimal flexibility. This makes this crate easier to use, at the price of not covering all use cases. You could say that this crate is the “instant food” of jaq crates: it is easy to use, but difficult to customise.
This crate is expected to change more frequently. However, because of its small amount of exposed functions, it may be easier to stay up-to-date with it than with its dependencies.
§Usage
Embedding jaq into your own application involves three steps:
- Compile a filter.
This takes a jq filter as string and parses & compiles it to
a filter ready to be executed by jaq.
You can do this with
data::compile, or withcompile_withif you need more flexibility. If this fails, e.g. due to parse errors, you can useload::FileReportsDispto pretty-print errors. - Read input data.
Every jq filter needs to be supplied with input.
This may be
read from an input stream (
std::io::Read) or parsed from a&str/bytes. You can do this with the functions in thefmts::readmodule, such asfmts::read::json::read_manyorfmts::read::json::parse_many. - Run the filter.
You can do this with
data::run. - Write output data (optional).
During or after filter execution, you may want to print output values.
You can do this with the functions in the
fmts::writemodule, such asfmts::write::write.
The main example in this crate shows you how to do all of this.
You can run it with cargo run --example main.
Re-exports§
Modules§
Functions§
- compile_
with - Compile a filter without access to external files.
- defs
- Definitions from
jaq_core,jaq_stdandjaq_json.