Serde-compatible streaming data-query language with a jq-like syntax

7 releases

0.2.0 Feb 19, 2023
0.1.5 Feb 5, 2023
0.1.4 Nov 2, 2021
0.1.3 Sep 13, 2020

#223 in Encoding

Download history 41/week @ 2023-02-13 43/week @ 2023-02-20 26/week @ 2023-02-27 40/week @ 2023-03-06 39/week @ 2023-03-13 24/week @ 2023-03-20 40/week @ 2023-03-27 47/week @ 2023-04-03 21/week @ 2023-04-10 40/week @ 2023-04-17 41/week @ 2023-04-24 17/week @ 2023-05-01 34/week @ 2023-05-08 34/week @ 2023-05-15 37/week @ 2023-05-22 67/week @ 2023-05-29

173 downloads per month
Used in rs-youtube


150 lines


Welcome to serde-query, a Rust library that lets you write jq-like queries for your data.

Why serde-query?

  1. Efficiency: With serde-query, you can efficiently extract exactly what you need without wasting the memory.
  2. Helpful error messages: When queries fail, you'll get clear, concise error messages that tell you where and why the failure happens.
  3. Flexibility: serde-query supports any serde-compatible data formats.

Getting started

To get started with serde-query, add it to your Rust project using Cargo:

cargo add serde-query

Or, add it to your Cargo.toml:

serde-query = "0.2.0"


Array queries

use serde_query::{DeserializeQuery, Query};

struct Data {
    authors: Vec<String>,
    count: usize,

let document = serde_json::json!({
    "commits": [
        { "author":    "Kou", "hash": 0x0202 },
        { "author": "Kasumi", "hash": 0x1013 },
        { "author": "Masaru", "hash": 0x0809 },
    "count": 3,

// You can use `Query<T>` as a `Deserialize` type for any `Deserializer`
// and convert the result to the desired type using `From`/`Into`.
let data: Data = serde_json::from_str::<Query<Data>>(&document)?.into();

assert_eq!(data.authors, vec!["Kou", "Kasumi", "Masaru"]);
assert_eq!(data.count, 3);


use serde_query::Deserialize;

#[derive(Debug, Deserialize)]
struct Data {
    // missing field
    author_name: String,
    // typo
    committer_name: String,
    // type error
    id: String,

let error = serde_json::from_str::<Data>(INPUT).unwrap_err();
Queries failed for fields: 'author_name', 'committer_name', 'id'
  1. Query for field 'author_name' failed at '.author': missing field 'name'
  2. Query for field 'committer_name' failed at '.commit': missing field 'commiter'
  3. Query for field 'id' failed at '.author.id': invalid type: integer `5635139`, expected a string at line 34 column 17


This library generates Rust types for each query segment (e.g., .commit, .commit.message, etc.), which may lead to binary bloat and longer compile time.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~10K SLoC