jsonpath_lib
Rust
버전 JsonPath 구현이다. Webassembly
와 Javascript
에서도 역시 동일한 API 인터페이스를 제공 한다.
It is an implementation for JsonPath written in Rust
. it provide the same API interface in Webassembly
and Javascript
also.
Why?
To enjoy Rust!
API
- jsonpath-wasm library
- jsonpath-rs library
- javascript - jsonpath.select(json: string|object, jsonpath: string)
- javascript - jsonpath.compile(jsonpath: string)
- javascript - jsonpath.selector(json: string|object)
- javascript - alloc_json, dealloc_json
- javascript-wasm - examples
- jsonpath_lib library
- 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 - examples
Simple time check - webassembly
Simple time check - native addon for NodeJs
With Javascript
jsonpath-wasm library
(not yet published jsonpath-wasm
)
// browser
import * as jsonpath from "jsonpath-wasm";
// NodeJs
const jsonpath = require;
jsonpath-rs library (Only NodeJS)
jsonpath-rs
is native addon for NodeJs
const jsonpath = require;
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 - alloc_json, dealloc_json
(not supported in jsonpath-rs
)
wasm-bindgen은 Javascript와 Webassembly 간 값을 주고받을 때 JSON 객체는 String으로 변환되기 때문에, 반복해서 사용되는 JSON 객체를 Webassembly 영역에 생성해 두면 성능에 도움이 된다.
Since wasm-bindgen converts JSON objects to String when exchanging values between Javascript and Webassembly, it is helpful to create repeated Json objects in Webassembly area.
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.;
With Rust (as library)
jsonpath_lib library
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_to_value.unwrap;
assert_eq!;
let result = selector.select_to_str.unwrap;
assert_eq!;
let result = selector..unwrap;
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!;