4 releases

0.1.3 Mar 23, 2024
0.1.2 Mar 20, 2024
0.1.1 Mar 17, 2024
0.1.0 Mar 4, 2024

#12 in #jq

MIT license

4MB
120K SLoC

C 115K SLoC // 0.1% comments Python 1.5K SLoC // 0.1% comments Happy 1K SLoC M4 437 SLoC // 0.4% comments Automake 404 SLoC // 0.1% comments C++ 334 SLoC // 0.1% comments jq 277 SLoC // 0.1% comments Jinja2 260 SLoC Shell 153 SLoC // 0.1% comments Lex 151 SLoC // 0.1% comments Rust 142 SLoC // 0.1% comments RPM Specfile 50 SLoC // 0.1% comments JavaScript 33 SLoC Batch 14 SLoC

j9

j9 provides a high-level API to run jq programs from Rust code, simplifying the execution of jq filters on JSON data.

Usage

To use j9, add it as a dependency in your Cargo.toml:

[dependencies]
j9 = "0.1.3"

Example

use j9;

fn main() -> anyhow::Result<()> {
    let json_str = r#"{ "number": 1 }"#;
    let jq = j9::run(".", json_str)?;
    println!("{:?}", jq);
    Ok(())
}

This example runs the simplest jq program (.) which outputs the input JSON unchanged. For more complex jq programs, simply replace "." with your jq filter.


lib.rs:

j9 is a Rust crate providing a high-level interface to the jq JSON processing library. It allows Rust applications to compile and execute jq scripts on JSON inputs, returning the processed results as Rust strings. This crate abstracts away the unsafe operations and direct FFI calls involved in using the jq library, offering a safe and idiomatic Rust API.

Dependencies