mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-06-12 07:31:25 +00:00
update example
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import * as jsonpath from "jsonpath-wasm";
|
||||
|
||||
|
||||
let jsonObj = {
|
||||
"school": {
|
||||
"friends": [
|
||||
@ -19,14 +18,21 @@ let ret = [
|
||||
{"name": "친구1", "age": 20}
|
||||
];
|
||||
|
||||
let selector = new jsonpath.Selector();
|
||||
selector.path('$..friends[0]');
|
||||
selector.value(jsonObj);
|
||||
const path = '$..friends[0]';
|
||||
|
||||
let selectToObj = selector.selectTo();
|
||||
let selectToString = selector.selectToStr();
|
||||
let ret1 = jsonpath.select(jsonObj, path);
|
||||
let ret2 = jsonpath.compile(path)(jsonObj);
|
||||
let ret3 = jsonpath.selector(jsonObj)(path);
|
||||
|
||||
let selector = new jsonpath.Selector();
|
||||
selector.path(path);
|
||||
selector.value(jsonObj);
|
||||
let ret4 = selector.select();
|
||||
|
||||
console.log(
|
||||
JSON.stringify(ret) == JSON.stringify(selectToObj),
|
||||
JSON.stringify(ret) == selectToString
|
||||
JSON.stringify(ret) == JSON.stringify(ret1),
|
||||
JSON.stringify(ret) == JSON.stringify(ret2),
|
||||
JSON.stringify(ret) == JSON.stringify(ret3),
|
||||
JSON.stringify(ret) == JSON.stringify(ret4)
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user