#json-path #json #query #lua #api-bindings

jsonpath_lib_polars_vendor

It is JsonPath engine written in Rust. it provide a similar API interface in Webassembly and Javascript too. - Webassembly Demo: https://freestrings.github.io/jsonpath

1 unstable release

Uses old Rust 2015

0.0.1 Feb 29, 2024

#42 in #json-path

Download history 3203/week @ 2024-06-08 2390/week @ 2024-06-15 3660/week @ 2024-06-22 4384/week @ 2024-06-29 3788/week @ 2024-07-06 3345/week @ 2024-07-13 4429/week @ 2024-07-20 4910/week @ 2024-07-27 4084/week @ 2024-08-03 4302/week @ 2024-08-10 3876/week @ 2024-08-17 4163/week @ 2024-08-24 4484/week @ 2024-08-31 5057/week @ 2024-09-07 4167/week @ 2024-09-14 4751/week @ 2024-09-21

19,116 downloads per month
Used in 28 crates (via polars-ops)

MIT license

300KB
6K SLoC

jsonpath_lib

VENDOR OF POLARS; DON'T USE.

See https://crates.io/crates/jsonpath_lib for the original.


lib.rs:

JsonPath implementation written in Rust.

Example

extern crate jsonpath_lib as jsonpath;
#[macro_use] extern crate serde_json;
let json_obj = json!({
    "store": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99
            },
            {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99
            },
            {
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99
            }
        ],
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    },
    "expensive": 10
});

let mut selector = jsonpath::selector(&json_obj);

assert_eq!(selector("$.store.book[*].author").unwrap(),
            vec![
                "Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien"
            ]);

assert_eq!(selector("$..author").unwrap(),
            vec![
                "Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien"
            ]);

assert_eq!(selector("$.store.*").unwrap(),
            vec![
                &json!([
                    { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 },
                    { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 },
                    { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 },
                    { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 }
                ]),
                &json!({ "color": "red", "price": 19.95 })
            ]);

assert_eq!(selector("$.store..price").unwrap(),
            vec![
                8.95, 12.99, 8.99, 22.99, 19.95
            ]);

assert_eq!(selector("$..book[2]").unwrap(),
            vec![
                &json!({
                    "category" : "fiction",
                    "author" : "Herman Melville",
                    "title" : "Moby Dick",
                    "isbn" : "0-553-21311-3",
                    "price" : 8.99
                })
            ]);

assert_eq!(selector("$..book[-2]").unwrap(),
            vec![
                &json!({
                    "category" : "fiction",
                    "author" : "Herman Melville",
                    "title" : "Moby Dick",
                    "isbn" : "0-553-21311-3",
                    "price" : 8.99
                })
            ]);

assert_eq!(selector("$..book[0,1]").unwrap(),
            vec![
                &json!({"category" : "reference","author" : "Nigel Rees","title" : "Sayings of the Century","price" : 8.95}),
                &json!({"category" : "fiction","author" : "Evelyn Waugh","title" : "Sword of Honour","price" : 12.99})
            ]);

assert_eq!(selector("$..book[:2]").unwrap(),
            vec![
                &json!({"category" : "reference","author" : "Nigel Rees","title" : "Sayings of the Century","price" : 8.95}),
                &json!({"category" : "fiction","author" : "Evelyn Waugh","title" : "Sword of Honour","price" : 12.99})
            ]);

assert_eq!(selector("$..book[:2]").unwrap(),
            vec![
                &json!({"category" : "reference","author" : "Nigel Rees","title" : "Sayings of the Century","price" : 8.95}),
                &json!({"category" : "fiction","author" : "Evelyn Waugh","title" : "Sword of Honour","price" : 12.99})
            ]);

assert_eq!(selector("$..book[?(@.isbn)]").unwrap(),
            vec![
                &json!({"category" : "fiction","author" : "Herman Melville","title" : "Moby Dick","isbn" : "0-553-21311-3","price" : 8.99}),
                &json!({"category" : "fiction","author" : "J. R. R. Tolkien","title" : "The Lord of the Rings","isbn" : "0-395-19395-8","price" : 22.99})
            ]);

assert_eq!(selector("$.store.book[?(@.price < 10)]").unwrap(),
            vec![
                &json!({"category" : "reference","author" : "Nigel Rees","title" : "Sayings of the Century","price" : 8.95}),
                &json!({"category" : "fiction","author" : "Herman Melville","title" : "Moby Dick","isbn" : "0-553-21311-3","price" : 8.99})
            ]);

Dependencies

~1.5–2.6MB
~50K SLoC