#json-query #query-language #query #jmespath

jmespatch

Rust implementation of JMESPath, a query language for JSON

1 unstable release

0.3.0 Apr 29, 2020

#2844 in Database interfaces

Download history 211/week @ 2024-07-22 168/week @ 2024-07-29 79/week @ 2024-08-05 105/week @ 2024-08-12 113/week @ 2024-08-19 94/week @ 2024-08-26 42/week @ 2024-09-02 68/week @ 2024-09-09 108/week @ 2024-09-16 137/week @ 2024-09-23 55/week @ 2024-09-30 124/week @ 2024-10-07 135/week @ 2024-10-14 74/week @ 2024-10-21 58/week @ 2024-10-28 103/week @ 2024-11-04

375 downloads per month
Used in 3 crates

MIT license

165KB
4K SLoC

JMESPatCh for Rust

Rust implementation of JMESPath, a query language for JSON.

Documentation

Difference with Jmespath (note path!=patch)

This repository was created with the only purpose of preparing a PR for the original jmespath.rs library.

However, after months of waiting for someone to comment on my PR, it is clear that the jmespath.rs project is in a dead state.

Consequently, I was forced to publish my fix to crates.io with the name jmespatch.

Compared to the original code, jmespatch:

  • upgrades the code to rust 2018 edition
  • replaces many .unwrap() calls with code that returns a Result to avoid panics when serde_json is not able to serialize/deserialize
  • modifies the Variable::Number to use a serde_json::Number instead of an f64 to mimic the same behavior of serde itself. This permits to use, whenever possible, u64 or i64 instead of f64
  • fixes an issue that does not allow to use jmespath.rs with serde_json 1.0.45 or greater
  • revamps the project structure to a cargo workspace
  • fixes a failing test in jmespath-cli
  • fixes all clippy warnings
  • updates all dependencies
  • modifies the benches to run on stable (no need any more for a nightly compiler to run cargo bench)

Status of this project

I will keep it until any sign of life is provided by the original jmespath.rs project.

I will not add new features, but every PR submitted is warmly welcomed.

Installing

This crate is on crates.io and can be used by adding jmespatch to the dependencies in your project's Cargo.toml.

[dependencies]
jmespatch = "0.3.0"

Examples

extern crate jmespatch;

let expr = jmespatch::compile("foo.bar").unwrap();

// Parse some JSON data into a JMESPath variable
let json_str = r#"{"foo": {"bar": true}}"#;
let data = jmespatch::Variable::from_json(json_str).unwrap();

// Search the data with the compiled expression
let result = expr.search(data).unwrap();
assert_eq!(true, result.as_boolean().unwrap());

Dependencies

~0.5–1MB
~21K SLoC