1
0
mirror of https://github.com/fluencelabs/jsonpath synced 2025-06-26 22:31:38 +00:00
Files
.idea
benchmark
docs
lua
src
tests
wasm
examples
browser
.gitignore
bootstrap.js
index.html
index.js
package-lock.json
package.json
webpack.config.js
nodejs-wasm
src
tests
www
www_bench
.gitignore
Cargo.toml
README.md
.gitignore
.travis.yml
Cargo.toml
LICENSE
README.md
bench.sh
build-wasm.sh
build.sh
coverage.sh
profiling.sh
jsonpath/wasm/examples/browser/index.js
2020-02-15 00:56:07 +09:00

39 lines
876 B
JavaScript

import * as jsonpath from "jsonpath-wasm";
let jsonObj = {
"school": {
"friends": [
{"name": "친구1", "age": 20},
{"name": "친구2", "age": 20}
]
},
"friends": [
{"name": "친구3", "age": 30},
{"name": "친구4"}
]
};
let ret = [
{"name": "친구3", "age": 30},
{"name": "친구1", "age": 20}
];
const path = '$..friends[0]';
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(ret1),
JSON.stringify(ret) == JSON.stringify(ret2),
JSON.stringify(ret) == JSON.stringify(ret3),
JSON.stringify(ret) == JSON.stringify(ret4)
);