mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-06-17 01:51:29 +00:00
.idea
benches
docs
examples
browser
.gitignore
bootstrap.js
index.html
index.js
package-lock.json
package.json
webpack.config.js
nodejs-rs
nodejs-wasm
nodejs
src
tests
wasm
.gitignore
.travis.yml
Cargo.toml
LICENSE
README.md
build-wasm.sh
build.sh
coverage.sh
profiling.sh
33 lines
681 B
JavaScript
33 lines
681 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}
|
||
|
];
|
||
|
|
||
|
let selector = new jsonpath.Selector();
|
||
|
selector.path('$..friends[0]');
|
||
|
selector.value(jsonObj);
|
||
|
|
||
|
let selectToObj = selector.selectTo();
|
||
|
let selectToString = selector.selectToStr();
|
||
|
|
||
|
console.log(
|
||
|
JSON.stringify(ret) == JSON.stringify(selectToObj),
|
||
|
JSON.stringify(ret) == selectToString
|
||
|
);
|