freestrings/jsonpath

Rust 버전 JsonPath 구현으로 Webassembly와 Javascript에서도 유사한 API 인터페이스를 제공 한다

JsonPath 구현으로 Webassembly와 Javascript에서도 유사한 API 인터페이스를 제공 한다

jsonpath_lib

Rust 버전 JsonPath 구현으로 WebassemblyJavascript에서도 유사한 API 인터페이스를 제공 한다.

It is JsonPath JsonPath engine written in Rust. it provide a similar API interface in Webassembly and Javascript too.

  • Webassembly Demo
  • NPM jsonpath-wasm - webassembly

Rust API

jsonpath_lib crate

Go to jsonpath_lib creates.io

Rust - jsonpath::Selector struct
Rust - jsonpath::SelectorMut struct
Rust - jsonpath::select(json: &serde_json::value::Value, jsonpath: &str)
Rust - jsonpath::select_as_str(json_str: &str, jsonpath: &str)
Rust - jsonpath::select_as(json_str: &str, jsonpath: &str)
Rust - jsonpath::PathCompiled::compile(jsonpath: &str)
Rust - jsonpath::selector(json: &serde_json::value::Value)
Rust - jsonpath::selector_as(json: &serde_json::value::Value)
Rust - jsonpath::delete(value: &Value, path: &str)
Rust - jsonpath::replace_with Value>(value: &Value, path: &str, fun: &mut F)

Rust - Other Examples

Javascript API

npm package
jsonpath-wasm

Goto jsonpath-wasm npmjs.org

jsonpath-wasm

wasm-bindgen 리턴 타입 제약 때문에 빌더 패턴은 지원하지 않는다.

It does not support builder-pattern due to the return type restriction of wasm-bindgen.

빌더 패턴 제약은 Selector class와 동일하다.

Javascript - jsonpath.select(json: string|object, jsonpath: string)
Javascript - jsonpath.compile(jsonpath: string)
Javascript - jsonpath.selector(json: string|object)
Javascript - jsonpath.deleteValue(json: string|object, path: string)
Javascript - jsonpath.replaceWith(json: string|object, path: string, fun: function(json: object) => json: object

Javascript - Other Examples

Issues

Collection of the latest Issues

gkorland

gkorland

Comment Icon0

Filter might return duplicate results when the internal objects are similar.

e.g. input JSON both objects have name == {"first":"A","middle":"A"}

When running:

The following result is returned:

It seems like the bug is in this code which compares all the candidates with all values and return each "parent" twice. https://github.com/freestrings/jsonpath/blob/1a84c5af9445e617a6deed14dadfaee13af0d95f/src/select/expr_term.rs#L107

ref https://github.com/RedisJSON/RedisJSON/issues/667

oshadmi

oshadmi

Comment Icon0

Path such as $.store.book[0]category Does not throw an error and is silently ignoring the surplus text category beyond the ] And is parsed as $.store.book[0]

Can be demonstrated also on https://freestrings.github.io/jsonpath/ The same value is returned with and without the surplus text category. Parser should throw an error on surplus text.

Notice that If there is a dot delimiter before the surplus text then everything is OK, e.g., $.store.book[0].category is working as expeced.

oshadmi

oshadmi

Comment Icon0

Adding a test such as the following, fails when a filter contains an OR expression with one of its operands being compared to a none-existing value, e.g., Slightly modifying an existing test named op_object_or_default in op.rs:

The selected result is empty, while it should be equal to the target json.

When removing the right operand || == 4 it succeeds (with filter >= 2)]" )

martinohmann

martinohmann

Comment Icon3

Hi,

I discovered the following panic while using SelectorMut::remove:

The jsonpath_lib version is 0.3.0. Here is a minimal reproducer:

I expected mutated to contain an empty array, but got this panic instead. Please note that when using .delete() instead of .remove() this code does not panic but produces the expected result of an array which contains only nulls.

I suspect that the array length isn't recalculated correctly after removing elements.

beltram

beltram

Comment Icon1

Hi, first of all thank you very much for this crate, helped me a lot.

I recently had to implement something where I had a bunch of partial json objects, each with its associated json path, and I had to build a json object from all those partial ones. In order to do this I had to parse each json path backwards in order to build my final json object. My code lies here.

But traits for doing this are not public. In the end, I would love to have those public use jsonpath_lib::{ParserNodeVisitor, ParserTokenHandler, ParseToken, StrRange};. I get that it is not the main purpose of the crate ; it is not aimed at being a parser.

I am willing to open a PR for that, I just wanted to have your consent (and explain why). WDYT ?

Thank you very much

MeirShpilraien

MeirShpilraien

Comment Icon6

Today the code assumes the underline json structure is serde_json::Value. We have a situation where this is not the case and we need to work with a custom structure. We still want to use this library with our structure. I was wondering if you will accept a PR that changes the code to work with any value that implement a defined trait, this way it can be use with serde_json::Value but with other structures as well. If you agree we can use this issue to define the details and I will be happy to contribute the PR.

omid

omid

enhancement
Comment Icon5

I would like to get the keys of the matching objects. For example, when I have the following JSON:

I want to get ["a","b"] with the following selector:

I know it's Jsonpath-Plus. But does this library support it? Is there any plan to go that way? Is there any way I achieve my goal with the current code?

glyn

glyn

Comment Icon0

@cburgmer's JSONPath comparison project is currently discussing some issues relating to a proposed implementation of JSONPath known as "Proposal A". May I encourage you to get involved if you are interested in influencing the direction or, indeed, if you want to make your own proposals.

Similarly, please join us in slack (invitation) for informal discussions on the comparison project and potential JSONPath standardisation.

coding-yogi

coding-yogi

Comment Icon0

All examples for this library are around vectors. Not a single example shows how to fetch just a specific value from json using jsonpath. If select returns vector everytime, how would program know if returned value was actually an json array or json value?

Also there is incosistency in the results returned by select and select_as_str

I have below json. For json path $.args.foo1, select_as_str() returns "[\"bar1\"]" which is ofcourse wrong and select() doesn't return anything!! but empty array

gkorland

gkorland

enhancement
Comment Icon5

Current replace_with code seems very inefficient

  1. Find all values.
  2. Compute all paths from values found in (1)
  3. Find values to replace again using paths from (2) to replace

It seems like the replace should account in step (1) while running select()

Versions

Find the latest versions by id

v0.3.0 - Jun 03, 2021

2d8e534 Move env-logger to dev-dependencies b012cbe Remove array_tools

v0.2.6 - Dec 16, 2020

  • merge #63 Provide an API for using compiled expressions
  • fix clippy errors

v0.2.5 - Apr 15, 2020

  • fix #37 Unit tests cleanup
  • fix #38 Bracket notation not supported inside filter expression
  • fix #39 Empty result for filter expression returns array of null
  • fix #40 Bracket notation after recursive descent does not recurse
  • fix #43 Failure to match "$..['']", "$..['ref']", but succeeds on $..ref

v0.2.4 - Feb 14, 2020

  • Add FFI module
  • Deprecated jsonpath-rs module
  • Fix small bugs

v0.2.3 - Jun 24, 2019

Bugs

  • Invalid wildcard filter results #7
  • fix broken build in osx. remove neon-serde be29571

Etc

  • remove indexmap crate 28ad9c9
  • bump library version up
    • cfg-if
    • console_error_panic_hook
    • we_alloc
    • env_logger
    • array_tool

v0.2.2 - Jun 20, 2019

New Feature

array filter

  • step 74666d2
  • multiple keys de97e2f
  • escaped quote notation 51deec6

Etc

  • improve error message fff0e86

Bugs

  • Results do not match other implementations #6

v0.2.0 - Jun 11, 2019

New feature

  • delete, replace

Changed

  • &Value is default return type

Removed feature

  • map function
  • filter module
  • ref_value module

Etc

  • jsonpath::select performance enhancement

v0.1.10 - Apr 13, 2019

jsonpath_lib v0.1.10

  • update README.md

jsonpath-wasm v0.1.3

  • npm package publish
  • add wasm-bingen-test unit test

jsonpath-rs v0.1.9

  • fix README.md link path

v0.1.9.2 - Apr 10, 2019

*Rust jsonpath_lib v0.1.9

  • bugfix: d955a16 d75b936 fix array filter
  • new feature: 30aa383 Selector struct

*NodeJs jsonpath-rs v0.1.7

  • new feature: d263e30 Selector class

v0.1.8 - Apr 05, 2019

*NodeJs jsonpath-rs v.0.1.6

  • select(json: string|object, jsonpath: string)
  • compile(jsonpath: string)
  • selector(json: string|object)
  • alloc_json, dealloc_json

*Rust jsontpath_lib v0.1.8

  • select(json: &serde_json::value::Value, jsonpath: &str)
  • select_as_str(json_str: &str, jsonpath: &str)
  • select_as<T: serde::de::DeserializeOwned>(json_str: &str, jsonpath: &str)
  • compile(jsonpath: &str)
  • selector(json: &serde_json::value::Value)
  • selector_as<T: serde::de::DeserializeOwned>(json: &serde_json::value::Value)

Information - Updated Mar 29, 2022

Stars: 73
Forks: 26
Issues: 30

serde-json for no_std programs

MIT license (LICENSE-MIT or

serde-json for no_std programs
JSON

591

JSON parser which picks up values directly without performing tokenization in Rust

This JSON parser is implemented based on an abstract that utilizes in memory indexing and parsing

JSON parser which picks up values directly without performing tokenization in Rust
JSON

3.0K

Serde JSON  

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically

Serde JSON  

JSON-E Rust data-struct paramter crate for lightweight embedded content with objects and much more

What makes JSON-e unique is that it extensive documentation and ease of use

JSON-E Rust data-struct paramter crate for lightweight embedded content with objects and much more

JSON-RPC library designed for async/await in Rust

Designed to be the successor to tracking issue for next stable release (0

JSON-RPC library designed for async/await in Rust
JSON

140

json_typegen - Rust types from JSON samples

json_typegen is a collection of tools for generating types from

json_typegen - Rust types from JSON samples

JSON File Parser

A CLI application that reads from a stream of JSON files, and computes some data-quality metrics

JSON File Parser

JSON Compilation Database

This crate provides support for reading and writing JSON compilation database files

JSON Compilation Database

json for some commands you can run (like yarn start, yarn build)

Run a create-rust-app project and then run yarn start

json for some commands you can run (like yarn start, yarn build)
Facebook Instagram Twitter GitHub Dribbble
Privacy