jsonpath_lib
Rust
버전 JsonPath 구현이다. Webassembly
와 Javascript
에서도 유사한 API 인터페이스를 제공 한다.
It is JsonPath JsonPath engine written in Rust
. it provide a similar API interface in Webassembly
and Javascript
also.
Rust API
- jsonpath_lib crate
- Rust - jsonpath::Selector 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<T:
serde::de::DeserializeOwned
>(json_str: &str, jsonpath: &str) - Rust - jsonpath::compile(jsonpath: &str)
- Rust - jsonpath::selector(json: &serde_json::value::Value)
- Rust - jsonpath::selector_as<T:
serde::de::DeserializeOwned
>(json: &serde_json::value::Value) - Rust - Other Examples
Javascript API
- npm package
- Javascript - jsonpath.Selector class
- Javascript - jsonpath.select(json: string|object, jsonpath: string)
- Javascript - jsonpath.compile(jsonpath: string)
- Javascript - jsonpath.selector(json: string|object)
- Javascript - allocJson, deallocJson (Webassembly Only)
- Javascript - Other Examples
Rust API
jsonpath_lib crate
extern crate jsonpath_lib as jsonpath;
extern crate serde_json;
Rust - jsonpath::Selector struct
let json_obj = json!;
let mut selector = new;
let result = selector
.path.unwrap
// .value_from_str(&serde_json::to_string(&json_obj).unwrap() /*&str*/).unwrap()
// .value_from(&json_obj /*&impl serde::ser::Serialize*/).unwrap()
.value.unwrap
.select_as_value.unwrap;
assert_eq!;
let result = selector.select_as_str.unwrap;
assert_eq!;
let result = selector..unwrap;
assert_eq!;
let _ = selector.map;
assert_eq!;
let _ = selector.value.unwrap
.map_as;
assert_eq!;
Rust - jsonpath::select(json: &serde_json::value::Value, jsonpath: &str)
let json_obj = json!;
let json = select.unwrap;
let ret = json!;
assert_eq!;
Rust - jsonpath::select_as_str(json: &str, jsonpath: &str)
let ret = select_as_str.unwrap;
assert_eq!;
Rust - jsonpath::select_as<T: serde::de::DeserializeOwned
>(json: &str, jsonpath: &str)
let ret: Person = select_as.unwrap;
let person = Person ;
assert_eq!;
Rust - jsonpath::compile(jsonpath: &str)
let mut template = compile;
let json_obj = json!;
let json = template.unwrap;
let ret = json!;
assert_eq!;
Rust - jsonpath::selector(json: &serde_json::value::Value)
let json_obj = json!;
let mut selector = selector;
let json = selector.unwrap;
let ret = json!;
assert_eq!;
let json = selector.unwrap;
let ret = json!;
assert_eq!;
Rust - jsonpath::selector_as<T: serde::de::DeserializeOwned
>(json: &serde_json::value::Value)
let json_obj = json!;
let mut selector = ;
let json = selector.unwrap;
let ret = vec!;
assert_eq!;
let json = selector.unwrap;
let ret = vec!;
assert_eq!;
Javascript API
npm package
jsonpath-wasm
// browser
import * as jsonpath from "jsonpath-wasm";
// NodeJs
const jsonpath = require;
jsonpath-rs (NodeJS only)
const jsonpath = require;
javascript - Selector class
jsonpath-wasm
wasm-bindgen
리턴 타입 제약 때문에 빌더 패턴은 지원하지 않는다.
It does not support builder-pattern
due to the return type
restriction of wasm-bindgen
.
let jsonObj = ;
let ret = ;
let selector = ;
selector.;
selector.;
let selectAsObj = selector.;
let selectAsString = selector.;
console.log;
selector.;
console.log;
// => true
jsonpath-rs
let jsonObj = ;
let ret = ;
let selector =
.
.;
let selectAsObj = selector.;
let selectAsString = selector.;
console.log;
// => true, true
Javascript - jsonpath.select(json: string|object, jsonpath: string)
let jsonObj = ;
let ret = ;
let selectAsString = jsonpath.;
let selectAsObj = jsonpath.;
console.log;
// => true, true
Javascript - jsonpath.compile(jsonpath: string)
let template = jsonpath.;
let jsonObj = ;
let ret = ;
let selectAsString = ;
let selectAsObj = ;
console.log;
// => true, true
let jsonObj2 = ;
let ret2 = ;
let selectAsString2 = ;
let selectAsObj2 = ;
console.log;
// => true, true
Javascript - jsonpath.selector(json: string|object)
let jsonObj = ;
let ret1 = ;
let ret2 = ;
let selector = jsonpath.;
// or as json string
// let selector = jsonpath.selector(JSON.stringify(jsonObj));
let select1 = ;
let select2 = ;
console.log;
// => true, true
Javascript - allocJson, deallocJson (Webassembly Only)
wasm-bindgen은 Javascript와 Webassembly간 값을 주고받을 때 JSON 객체는 String으로 변환되기 때문에, 반복해서 사용되는 JSON 객체는 Webassembly 영역에 생성해 두면 성능에 도움이 된다.
Since wasm-bindgen converts JSON objects to String when exchanging values between Javascript and Webassembly, creating frequently used JSON objects in the WebAssembly area helps performance.
const jsonpath = require;
let jsonObj = ;
// allocate jsonObj in webassembly
let ptr = jsonpath.;
// `0` is invalid pointer
if
let path = '$..friends[0]';
let template = jsonpath.;
let selector = jsonpath.;
// create selector as pointer
let ptrSelector = jsonpath.;
let ret1 =
let ret2 =
let ret3 = ;
// select as pointer
let ret4 = ;
let ret5 = jsonpath.;
// select as pointer
let ret6 = jsonpath.;
console.log;
// => true true true true true
jsonpath.;