json-query
This rust crate provides programmatic access to jq 1.6 via its C api.
By leveraging jq we can extract and transform data from a json string using jq's filtering dsl.
use json_query;
// ...
let res = run;
assert_eq!;
The return values from the run method are json strings, and as such will need to be parsed if you want to work with the actual data types being represented. As such, you may want to pair this crate with serde_json or similar.
For example, here we want to extract the numbers from a set of objects:
use json_query;
use ;
// ...
let data = json!;
let query = "[.movies[].year]";
// program output as a json string...
let output = run.unwrap;
// ... parse via serde
let parsed: = from_str.unwrap;
assert_eq!;
Barely any of the options or flags available from the jq cli are exposed currently. Literally all that is provided is the ability to execute a jq program on a blob of json. Please pardon my dust as I sort out the details.
Linking to libjq
When the bundled
feature is enabled (on by default) libjq
is provided and
linked statically by jq-sys and jq-src
which require having autotools and gcc in PATH
to build.
If you disable the bundled
feature, you will need to ensure your crate
links to libjq
in order for the bindings to work.
For this you may need to add a build.rs
script if you don't have one already.
Changelog
v0.1.1 (2019-01-14)
- Added extra links to cargo manifest.
- Added some basic docs.
- Added a
bundled
feature to opt in or out of using the bundled source.
v0.1.0 (2019-01-13)
Initial release.