forked from JSONPath-Plus/JSONPath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.properties.js
More file actions
33 lines (30 loc) · 1.18 KB
/
test.properties.js
File metadata and controls
33 lines (30 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
describe('JSONPath - Properties', function () {
const json = {
"test1": {
"test2": {
"test3.test4.test5": {
"test7": "value"
}
}
},
"datafield": [
{"tag": "035", "subfield": {"@code": "a", "#text": "1879"}},
{"@tag": "042", "subfield": {"@code": "a", "#text": "5555"}},
{"@tag": "045", "045": "secret"}
]
};
it('Periods within properties', () => {
const expected = {"test7": "value"};
const result = jsonpath({json, path: "$.test1.test2['test3.test4.test5']", wrap: false});
assert.deepEqual(expected, result);
});
it('At signs within properties', () => {
let result = jsonpath({json, path: "$.datafield[?(@.tag=='035')]", wrap: false});
assert.deepEqual([json.datafield[0]], result);
result = jsonpath({json, path: "$.datafield[?(@['@tag']=='042')]", wrap: false});
assert.deepEqual([json.datafield[1]], result);
result = jsonpath({json, path: "$.datafield[2][(@['@tag'])]", wrap: false});
assert.deepEqual(json.datafield[2]['045'], result);
});
});