forked from JSONPath-Plus/JSONPath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample-page.html
More file actions
37 lines (27 loc) · 1.1 KB
/
sample-page.html
File metadata and controls
37 lines (27 loc) · 1.1 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
34
35
36
37
<html>
<head>
<title>JSON Path Examples</title>
<script type="text/javascript" src='lib/jsonpath.js'></script>
<script type="text/javascript" src='json-data.js'></script>
<script type="text/javascript">
(function() {
var output = [];
// output: Nigel Rees,Evelyn Waugh,Herman Melville,J. R. R. Tolkien
output.push(jsonPath.eval(jsonData, "$..author")); //all authors
// output: red
output.push(jsonPath.eval(jsonData, "$.store.*")[1]['color']);
// output: 8.95,12.99,8.99,22.99,19.95
output.push(jsonPath.eval(jsonData, "$.store..price")); //price of everything in the store
// output: Herman Melville
output.push(jsonPath.eval(jsonData, "$..book[2]")[0]['author']); //author of third book
// output.push(jsonPath.eval(jsonData, "$..book[0,1]")); //the first two books
//output: 2
output.push(jsonPath.eval(jsonData, "$..book[?(@.price<10)]").length); //filter all books cheaper than 10
for(var i=0,len=output.length; i < len; i++){
document.write(output[i]);
document.write("<br/><br/>");
}
})();
</script>
</head>
</html>