#json-query #json-filter #json

no-std jq

jq.rs transforms JSON using the jq language

6 releases (3 breaking)

Uses new Rust 2024

0.3.1 Oct 30, 2026
0.3.0 Oct 30, 2026
0.2.0 Oct 5, 2026
0.1.1 Oct 4, 2026
0.0.0 May 24, 2025

#1855 in Template engine

Download history 49/week @ 2026-08-13 25/week @ 2026-08-20 31/week @ 2026-08-27 55/week @ 2026-09-03 121/week @ 2026-09-10 1008/week @ 2026-09-17 7/week @ 2026-09-24 2582/week @ 2026-10-01 3418/week @ 2026-10-08 3235/week @ 2026-10-15 3432/week @ 2026-10-22 3472/week @ 2026-10-29 3402/week @ 2026-11-05 3491/week @ 2026-11-12 3446/week @ 2026-11-19 3477/week @ 2026-11-26

14,309 downloads per month
Used in 11 crates

Unlicense

66KB
1K SLoC

Rust 1K SLoC // 0.0% comments Liquid 107 SLoC JavaScript 12 SLoC

jq.rs

License Compatibility Package on Crates.io Documentation

jq.rs brings jq-style JSON filtering to Rust.

[Features] | [Prerequisites] | [Installation] | [Examples] | [Reference] | [Development]


✨ Features

  • Compile filters once and reuse them with the in-process jaq backend.
  • Work with JSON strings or serde_json::Value inputs.
  • Return the first result, collect all results, or visit results incrementally.
  • Bind named JSON variables and supply auxiliary inputs to input and inputs.
  • Choose jaq or the upstream jq executable through Cargo feature flags.
  • Supports no_std with heap allocation.
  • Cuts red tape: 100% free and unencumbered public domain software.

🛠️ Prerequisites

  • Rust 1.97+ (2024 edition)
  • A jq executable in the PATH (only when using the subprocess backend)

⬇️ Installation

Install the latest release from Crates.io:

cargo add jq serde_json

For the development version documented here, including named bindings and the subprocess backend:

cargo add jq --git https://github.com/dryrust/jq.rs
cargo add serde_json

👉 Examples

Filtering JSON

Parse a filter once and reuse it. Choose the first result or collect them all:

use jq::{JsonFilter, JsonFilterError};
use serde_json::json;

fn main() -> Result<(), JsonFilterError> {
    let filter: JsonFilter = ".items[] | .name".parse()?;
    let input = r#"{"items": [{"name": "Ada"}, {"name": "Lin"}]}"#;

    assert_eq!(
        filter.filter_json_str(input)?,
        json!("Ada"),
    );
    assert_eq!(
        filter.filter_json_str_all(input)?,
        [json!("Ada"), json!("Lin")],
    );
    Ok(())
}

Binding Variables

Pass values as named variables without interpolating them into filter source:

use jq::{JsonFilter, JsonFilterError};
use serde_json::json;

fn main() -> Result<(), JsonFilterError> {
    let mut filter = JsonFilter::with_bindings(
        ".[] | select(. >= $minimum)",
        [("minimum", json!(10))],
    )?;
    assert_eq!(
        filter.filter_json_all(json!([5, 12, 20]))?,
        [json!(12), json!(20)],
    );

    filter.set_bindings([("minimum", json!(15))])?;
    assert_eq!(filter.filter_json_all(json!([5, 12, 20]))?, [json!(20)]);
    Ok(())
}

📚 Reference

Rust API

JsonFilter compiles and evaluates filters; JsonFilterError reports failures. See the API documentation for method contracts and backend behavior, or run cargo doc --open for the development version.

Feature Flags

Feature Purpose
jaq In-process Rust backend.
jq Upstream jq subprocess backend; enables std.
std Standard-library support and jaq's optional functions.
env Exposes host environment variables to env; enables std.
import Lets the jq backend load modules and JSON data files.
log Forwards jaq's stderr and debug messages to log.
all Enables both backends.

Defaults enable all and std. env and import are opt-in, as they expose secrets in environment variables and files; never enable them for untrusted programs. jaq takes precedence when both backends are enabled. To select the subprocess backend, set default-features = false and features = ["jq"] on the dependency. For no_std with heap allocation, use default-features = false and features = ["jaq"] instead.

Both backends use the same Rust API, but their jq language behavior can differ.

👨‍💻 Development

git clone https://github.com/dryrust/jq.rs.git

This README was generated with Readmer.


Share on X Share on Reddit Share on Hacker News Share on Facebook Share on LinkedIn

Dependencies

~0–2.1MB
~35K SLoC