An implementation of the JSONPath A spec in Rust, with several extensions added on

Overview

Rust JSONPath Plus

crates.io Documentation MIT/Apache-2 licensed

An implementation of the JSONPath A spec in Rust, with several extensions added on.

This library also supports retrieving AST analysis of compiled paths, so users may implement syntax highlighting or nice error reporting on top of it.

Extensions

  • Parent selector ^, used as $.a.b.^ or $['a']['b'][^]. Matches the parent of the currently selected object.
  • Subpath selectors, used as $['a'][$.b.id] or $['a'][@.sum.id]. Evaluates the subpath, then selects items with keys same as the result of the subpath.
  • ID selector ~, used at the end of the path as @.a.b~ or $['a']['b']~. Can be used in filters to compare against the ID of a matched item. Doesn't yet work at the top level.
You might also like...
Fontdue - The fastest font renderer in the world, written in pure rust.
Fontdue - The fastest font renderer in the world, written in pure rust.

Fontdue is a simple, no_std (does not use the standard library for portability), pure Rust, TrueType (.ttf/.ttc) & OpenType (.otf) font rasterizer and layout tool. It strives to make interacting with fonts as fast as possible, and currently has the lowest end to end latency for a font rasterizer.

CLI tool to convert HOCON into valid JSON or YAML written in Rust.

{hocon:vert} CLI Tool to convert HOCON into valid JSON or YAML. Under normal circumstances this is mostly not needed because hocon configs are parsed

Typify - Compile JSON Schema documents into Rust types.

Typify Compile JSON Schema documents into Rust types. This can be used ... via the macro import_types!("types.json") to generate Rust types directly i

A easy and declarative way to test JSON input in Rust.

assert_json A easy and declarative way to test JSON input in Rust. assert_json is a Rust macro heavily inspired by serde json macro. Instead of creati

Hjson for Rust
Hjson for Rust

hjson-rust for serde { # specify rate in requests/second (because comments are helpful!) rate: 1000 // prefer c-style comments? /* feeling ol

A small rust database that uses json in memory.

Tiny Query Database (TQDB) TQDB is a small library for creating a query-able database that is encoded with json. The library is well tested (~96.30% c

A JSON Query Language CLI tool built with Rust 🦀

JQL A JSON Query Language CLI tool built with Rust 🦀 📜 Core philosophy 📦 Stay lightweight 🎮 Keep its features as simple as possible 🧠 Avoid redun

An HCL serializer/deserializer for rust

hcl-rs This crate provides functionality to deserialize, serialize and manipulate HCL data. The main types are Deserializer for deserializing data, Se

Rust libraries and tools to help with interoperability and testing of serialization formats based on Serde.

The repository zefchain/serde-reflection is based on Facebook's repository novifinancial/serde-reflection. We are now maintaining the project here and

Comments
  • try_replace panics with index out of bounds when deleting value

    try_replace panics with index out of bounds when deleting value

    Test to reproduce:

        #[test]
        fn test_delete_in_try_replace() -> Result<(), ParseError> {
            let input = json!({"list": ["BLUE", "ORANGE", "GREEN", "RED"]});
            let output = JsonPath::compile("$.list[*]")?.try_replace(&input, |_| None);
            assert_eq!(output, json!({"list": []}));
            Ok(())
        }
    

    leads to error:

    thread 'using_jsonpath_plus::tests::test_delete_in_try_replace' panicked at 'index out of bounds: the len is 2 but the index is 2', /Users/sp/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonpath-plus-0.1.3/src/utils.rs:60:30
    stack backtrace:
       0: rust_begin_unwind
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/panicking.rs:498:5
       1: core::panicking::panic_fmt
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/panicking.rs:107:14
       2: core::panicking::panic_bounds_check
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/panicking.rs:75:5
       3: <usize as core::slice::index::SliceIndex<[T]>>::index
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/slice/index.rs:184:10
       4: core::slice::index::<impl core::ops::index::Index<I> for [T]>::index
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/slice/index.rs:15:9
       5: <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/alloc/src/vec/mod.rs:2528:9
       6: jsonpath_plus::utils::try_replace_paths
                 at /Users/sp/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonpath-plus-0.1.3/src/utils.rs:60:30
       7: jsonpath_plus::<impl jsonpath_plus::ast::Path>::try_replace
                 at /Users/sp/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonpath-plus-0.1.3/src/lib.rs:145:9
       8: jsonpath_filter::using_jsonpath_plus::tests::test_delete_in_try_replace
                 at ./src/using_jsonpath_plus.rs:216:22
       9: jsonpath_filter::using_jsonpath_plus::tests::test_delete_in_try_replace::{{closure}}
                 at ./src/using_jsonpath_plus.rs:214:5
      10: core::ops::function::FnOnce::call_once
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/ops/function.rs:227:5
      11: core::ops::function::FnOnce::call_once
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/ops/function.rs:227:5
    
    bug 
    opened by stefanpieck 3
  • Using replace leads to a panic

    Using replace leads to a panic

    For my use case I need to remove values for specific conditions.

    I tried to do that by use the replace method, but ran into a panic when using replace at all.

    Occured on version 0.1.0

    Here a short test to reproduce:

    #[test]
    fn test_replace() {
        let input = json!({"list": ["red", "green", "blue"]});
        let path = jsonpath_plus::JsonPath::compile("$.list[*]").expect("jsonpath is valid");
        let output = path.replace(&input, |_| json!("black"));
        assert_eq!(output, json!({"list": ["black", "black", "black"]}))
    }
    

    The output was:

    thread 'tests::test_replace' panicked at 'explicit panic', /Users/sp/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonpath-plus-0.1.0/src/eval.rs:39:18
    stack backtrace:
       0: rust_begin_unwind
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/std/src/panicking.rs:498:5
       1: core::panicking::panic_fmt
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/panicking.rs:107:14
       2: core::panicking::panic
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/panicking.rs:48:5
       3: jsonpath_plus::eval::Idx::as_string
                 at /Users/sp/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonpath-plus-0.1.0/src/eval.rs:39:18
       4: jsonpath_plus::resolve_path
                 at /Users/sp/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonpath-plus-0.1.0/src/lib.rs:40:53
       5: jsonpath_plus::<impl jsonpath_plus::ast::Path>::replace
                 at /Users/sp/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonpath-plus-0.1.0/src/lib.rs:132:30
       6: jsonpath_filter::tests::test_replace
                 at ./src/lib.rs:223:22
       7: jsonpath_filter::tests::test_replace::{{closure}}
                 at ./src/lib.rs:220:5
       8: core::ops::function::FnOnce::call_once
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/ops/function.rs:227:5
       9: core::ops::function::FnOnce::call_once
                 at /rustc/db9d1b20bba1968c1ec1fc49616d4742c1725b4b/library/core/src/ops/function.rs:227:5
    note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    test tests::test_replace ... FAILED
    
    bug 
    opened by stefanpieck 2
  • Improve crate-level documentation

    Improve crate-level documentation

    Both the README and the create-level doc text could use some work. Examples, feature description, and either a description of the syntax or a link to an external one (or both).

    documentation help wanted 
    opened by CraftSpider 0
Owner
Rune Tynan
An SE graduate, and continuous FIRST robotics member. Check out my archenemy, @cruxicheiros, and fellow code makers @wundrweapon @sedezee
Rune Tynan
JSON implementation in Rust

json-rust Parse and serialize JSON with ease. Changelog - Complete Documentation - Cargo - Repository Why? JSON is a very loose format where anything

Maciej Hirsz 500 Dec 21, 2022
Pure Go implementation of jq

gojq Pure Go implementation of jq This is an implementation of jq command written in Go language. You can also embed gojq as a library to your Go prod

itchyny 2.4k Jan 8, 2023
An alternative implementation of the OP Stack's Cannon, a MIPS emulator for the EVM.

An alternative implementation of the OP Stack's Cannon in Rust. What's a Cannon? • Overview • Credits • Benchmarks • Contributing • Documentation • Do

Anton Systems 34 Oct 4, 2023
JSON parser which picks up values directly without performing tokenization in Rust

Pikkr JSON parser which picks up values directly without performing tokenization in Rust Abstract Pikkr is a JSON parser which picks up values directl

Pikkr 615 Dec 29, 2022
Strongly typed JSON library for Rust

Serde JSON   Serde is a framework for serializing and deserializing Rust data structures efficiently and generically. [dependencies] serde_json = "1.0

null 3.6k Jan 5, 2023
Rust port of simdjson

SIMD Json for Rust   Rust port of extremely fast simdjson JSON parser with serde compatibility. readme (for real!) simdjson version Currently tracking

null 737 Dec 30, 2022
Rust port of gjson,get JSON value by dotpath syntax

A-JSON Read JSON values quickly - Rust JSON Parser change name to AJSON, see issue Inspiration comes from gjson in golang Installation Add it to your

Chen Jiaju 90 Dec 6, 2022
Get JSON values quickly - JSON parser for Rust

get json values quickly GJSON is a Rust crate that provides a fast and simple way to get values from a json document. It has features such as one line

Josh Baker 160 Dec 29, 2022
This library is a pull parser for CommonMark, written in Rust

This library is a pull parser for CommonMark, written in Rust. It comes with a simple command-line tool, useful for rendering to HTML, and is also designed to be easy to use from as a library.

Raph Levien 1.5k Jan 1, 2023
A rust script to convert a better bibtex json file from Zotero into nice organised notes in Obsidian

Zotero to Obsidian script This is a script that takes a better bibtex JSON file exported by Zotero and generates an organised collection of reference

Sashin Exists 3 Oct 9, 2022