update example

This commit is contained in:
freestrings
2019-06-23 23:59:18 +09:00
parent 967df1b787
commit 59dad2ea02
9 changed files with 159 additions and 60 deletions

View File

@ -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)
);