mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-06-12 23:51:26 +00:00
Move javascript examples directory under wasm
This commit is contained in:
2
wasm/examples/nodejs-wasm/.gitignore
vendored
Normal file
2
wasm/examples/nodejs-wasm/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
dist
|
37
wasm/examples/nodejs-wasm/index.js
Normal file
37
wasm/examples/nodejs-wasm/index.js
Normal file
@ -0,0 +1,37 @@
|
||||
const jsonpath = require('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)
|
||||
);
|
12
wasm/examples/nodejs-wasm/package-lock.json
generated
Normal file
12
wasm/examples/nodejs-wasm/package-lock.json
generated
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "jsonpath-wasm-nodejs-example",
|
||||
"requires": true,
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"jsonpath-wasm": {
|
||||
"version": "0.2.4",
|
||||
"resolved": "https://registry.npmjs.org/jsonpath-wasm/-/jsonpath-wasm-0.2.4.tgz",
|
||||
"integrity": "sha512-sxvPEFMpAoNjxUQOkJmVyE3dKX7v4ebX5TkWKguyHteZpHJKlMQbgPKFYL0X3SIU7wAstpOl6hVODLThVmJf1w=="
|
||||
}
|
||||
}
|
||||
}
|
9
wasm/examples/nodejs-wasm/package.json
Normal file
9
wasm/examples/nodejs-wasm/package.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "jsonpath-wasm-nodejs-example",
|
||||
"scripts": {
|
||||
"start": "node index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"jsonpath-wasm": "^0.2.4"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user