mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-06-21 20:01:39 +00:00
nodejs/README.md - 정리, version 0.1.1
This commit is contained in:
@ -27,4 +27,73 @@ describe('select test', () => {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('filter test', () => {
|
||||
it('complex filter1', (done) => {
|
||||
let json = {
|
||||
'store': {
|
||||
'book': [
|
||||
{
|
||||
'category': 'reference',
|
||||
'author': 'Nigel Rees',
|
||||
'title': 'Sayings of the Century',
|
||||
'price': 8.95,
|
||||
},
|
||||
{
|
||||
'category': 'fiction',
|
||||
'author': 'Evelyn Waugh',
|
||||
'title': 'Sword of Honour',
|
||||
'price': 12.99,
|
||||
},
|
||||
{
|
||||
'category': 'fiction',
|
||||
'author': 'Herman Melville',
|
||||
'title': 'Moby Dick',
|
||||
'isbn': '0-553-21311-3',
|
||||
'price': 8.99,
|
||||
},
|
||||
{
|
||||
'category': 'fiction',
|
||||
'author': 'J. R. R. Tolkien',
|
||||
'title': 'The Lord of the Rings',
|
||||
'isbn': '0-395-19395-8',
|
||||
'price': 22.99,
|
||||
},
|
||||
],
|
||||
'bicycle': {
|
||||
'color': 'red',
|
||||
'price': 19.95,
|
||||
},
|
||||
},
|
||||
'expensive': 10,
|
||||
};
|
||||
|
||||
let target = [
|
||||
{
|
||||
category: 'fiction',
|
||||
author: 'Evelyn Waugh',
|
||||
title: 'Sword of Honour',
|
||||
price: 12.99,
|
||||
},
|
||||
{
|
||||
category: 'fiction',
|
||||
author: 'J. R. R. Tolkien',
|
||||
title: 'The Lord of the Rings',
|
||||
isbn: '0-395-19395-8',
|
||||
price: 22.99,
|
||||
},
|
||||
{
|
||||
category: 'reference',
|
||||
author: 'Nigel Rees',
|
||||
title: 'Sayings of the Century',
|
||||
price: 8.95,
|
||||
}]
|
||||
;
|
||||
|
||||
let result = jsonpath.select(json, '$..book[?((@.price == 12.99 || $.store.bicycle.price < @.price) || @.category == "reference")]');
|
||||
if (JSON.stringify(result) === JSON.stringify(target)) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user