|
6 | 6 | JSON query and transformation language
|
7 | 7 |
|
8 | 8 | ##Introduction
|
9 |
| -The primary purpose of this language is to extract values from JSON documents, with the |
10 |
| -additional capabilities to combine these values using a set of basic functions |
11 |
| -and operators, and also the ability to format the output into any arbitrary JSON structure. |
| 9 | +JSONata is a lightweight query and transformation language for JSON data. |
| 10 | +Inspired by the 'location path' semantics of XPath 3.1, it allows sophisticated |
| 11 | +queries to be expressed in a compact and intuitive notation. A rich complement of built in |
| 12 | +operators and functions is provided for manipulating and combining extracted |
| 13 | +data, and the results of queries can be formatted into any JSON output structure |
| 14 | +using familiar JSON object and array syntax. |
| 15 | +Coupled with the facility to create user defined functions, advanced expressions |
| 16 | +can be built to tackle any JSON query and transformation task. |
| 17 | + |
| 18 | +<p><iframe width="400" height="300" src="https://www.youtube.com/embed/ZBaK40rtIBM" frameborder="0" allowfullscreen></iframe><br /> |
| 19 | +<br /></p> |
| 20 | + |
| 21 | +Try it out at [http://try.jsonata.org/](http://try.jsonata.org/) |
12 | 22 |
|
13 | 23 | ##Install
|
14 | 24 | - `npm install jsonata`
|
15 | 25 |
|
16 | 26 | ##Usage
|
17 |
| -In node.js (works in v0.10 and later): |
18 |
| -``` |
| 27 | +In node.js: |
| 28 | +```javascript |
19 | 29 | var jsonata = require("jsonata");
|
20 | 30 | var data = { "example": [ {"value": 4}, {"value": 7}, {"value": 13}] };
|
21 | 31 | var expression = "$sum(example.value)";
|
22 | 32 | var result = jsonata(expression).evaluate(data); // returns 24
|
23 | 33 | ```
|
24 | 34 |
|
25 |
| -In a browser (works in latest Chrome, Firefox, Safari): |
26 |
| -``` |
| 35 | +In a browser: |
| 36 | +```html |
27 | 37 | <!DOCTYPE html>
|
28 | 38 | <html lang="en">
|
29 | 39 | <head>
|
30 | 40 | <meta charset="UTF-8">
|
31 | 41 | <title>JSONata test</title>
|
32 | 42 | <script src="lib/jsonata.js"></script>
|
| 43 | + <script> |
| 44 | + function greeting() { |
| 45 | + var json = JSON.parse(document.getElementById('json').value); |
| 46 | + var result = jsonata('"Hello, " & name').evaluate(json); |
| 47 | + document.getElementById('greeting').innerHTML = result; |
| 48 | + } |
| 49 | + </script> |
33 | 50 | </head>
|
34 | 51 | <body>
|
35 |
| -<button onclick="alert(jsonata('[1..10]').evaluate())">Click me</button> |
| 52 | + <textarea id="json">{ "name": "Wilbur" }</textarea> |
| 53 | + <button onclick="greeting()">Click me</button> |
| 54 | + <p id="greeting"></p> |
36 | 55 | </body>
|
37 | 56 | </html>
|
38 | 57 | ```
|
@@ -65,11 +84,12 @@ and any other relevant information, including a meaningful message string.
|
65 | 84 |
|
66 | 85 | For example:
|
67 | 86 |
|
68 |
| -`{ "position": 16, "token": "}", "value": "]", "message": "Syntax error: expected ']' got '}' at column 16" }` |
| 87 | +`{ "position": 16, "token": "}", "value": "]", "message": "Syntax error: expected ']' got '}'" }` |
69 | 88 |
|
70 | 89 | ##More Information
|
71 | 90 | Tutorial [tutorial.md](tutorial.md)
|
72 | 91 | Function library [functions.md](functions.md)
|
| 92 | +JSONata [Tech Talk](https://developer.ibm.com/open/videos/dw-open-tech-talk-jsonata/) |
73 | 93 |
|
74 | 94 | ## Contributing
|
75 | 95 | See the [CONTRIBUTING.md](CONTRIBUTING.md) for details of how to contribute to this repo.
|
0 commit comments