mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-06-17 18:11:28 +00:00
jsonpath-rs add "map", "get" function
This commit is contained in:
@ -444,7 +444,7 @@ describe('README test', () => {
|
||||
let selector = new jsonpath.Selector().value(jsonObj);
|
||||
|
||||
{
|
||||
let jsonObj = selector.path('$..[?(@.age >= 30)]').selectTo();
|
||||
let jsonObj = selector.path('$..[?(@.age >= 30)]').selectAs();
|
||||
let resultObj = [{"name": "친구3", "age": 30}];
|
||||
if(JSON.stringify(jsonObj) !== JSON.stringify(resultObj)) {
|
||||
throw 'jsonpath.Selector: $..[?(@.age >= 30)]';
|
||||
@ -452,7 +452,7 @@ describe('README test', () => {
|
||||
}
|
||||
|
||||
{
|
||||
let jsonObj = selector.path('$..[?(@.age == 20)]').selectTo();
|
||||
let jsonObj = selector.path('$..[?(@.age == 20)]').selectAs();
|
||||
let resultObj = [{"name": "친구1", "age": 20}, {"name": "친구2", "age": 20}];
|
||||
if(JSON.stringify(jsonObj) !== JSON.stringify(resultObj)) {
|
||||
throw 'jsonpath.Selector: $..[?(@.age >= 20)]';
|
||||
@ -460,13 +460,32 @@ describe('README test', () => {
|
||||
}
|
||||
|
||||
{
|
||||
let jsonObj = selector.value({"friends": [ {"name": "친구5", "age": 20} ]}).selectTo();
|
||||
let jsonObj = selector.value({"friends": [ {"name": "친구5", "age": 20} ]}).selectAs();
|
||||
let resultObj = [{"name": "친구5", "age": 20}];
|
||||
if(JSON.stringify(jsonObj) !== JSON.stringify(resultObj)) {
|
||||
throw 'jsonpath.Selector: change value';
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let jsonObj1 = selector.value(jsonObj).map(function(v) {
|
||||
let f1 = v[0];
|
||||
f1.age = 30;
|
||||
return v;
|
||||
}).get();
|
||||
|
||||
let resultObj1 = [{"name": "친구1", "age": 30}, {"name": "친구2", "age": 20}];
|
||||
if(JSON.stringify(jsonObj1) !== JSON.stringify(resultObj1)) {
|
||||
throw 'jsonpath.Selector.map';
|
||||
}
|
||||
|
||||
let jsonObj2 = selector.path('$..[?(@.age == 20)]').selectAs();
|
||||
let resultObj2 = [{"name": "친구2", "age": 20}];
|
||||
if(JSON.stringify(jsonObj2) !== JSON.stringify(resultObj2)) {
|
||||
throw 'jsonpath.Selector.map and then select';
|
||||
}
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user