Skip to content

Commit 002fb6a

Browse files
andrew-colemanmattbaileyuk
authored andcommitted
Changes to behaviour of object constructor and result arrays (#31)
* Added [] syntax to maintain singleton result arrays; changed behaviour of object constructor * Update tutorial.md Fix typo
1 parent 4bc8919 commit 002fb6a

File tree

4 files changed

+354
-252
lines changed

4 files changed

+354
-252
lines changed

README.md

+29-9
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,52 @@
66
JSON query and transformation language
77

88
##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/)
1222

1323
##Install
1424
- `npm install jsonata`
1525

1626
##Usage
17-
In node.js (works in v0.10 and later):
18-
```
27+
In node.js:
28+
```javascript
1929
var jsonata = require("jsonata");
2030
var data = { "example": [ {"value": 4}, {"value": 7}, {"value": 13}] };
2131
var expression = "$sum(example.value)";
2232
var result = jsonata(expression).evaluate(data); // returns 24
2333
```
2434

25-
In a browser (works in latest Chrome, Firefox, Safari):
26-
```
35+
In a browser:
36+
```html
2737
<!DOCTYPE html>
2838
<html lang="en">
2939
<head>
3040
<meta charset="UTF-8">
3141
<title>JSONata test</title>
3242
<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>
3350
</head>
3451
<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>
3655
</body>
3756
</html>
3857
```
@@ -65,11 +84,12 @@ and any other relevant information, including a meaningful message string.
6584

6685
For example:
6786

68-
`{ "position": 16, "token": "}", "value": "]", "message": "Syntax error: expected ']' got '}' at column 16" }`
87+
`{ "position": 16, "token": "}", "value": "]", "message": "Syntax error: expected ']' got '}'" }`
6988

7089
##More Information
7190
Tutorial [tutorial.md](tutorial.md)
7291
Function library [functions.md](functions.md)
92+
JSONata [Tech Talk](https://developer.ibm.com/open/videos/dw-open-tech-talk-jsonata/)
7393

7494
## Contributing
7595
See the [CONTRIBUTING.md](CONTRIBUTING.md) for details of how to contribute to this repo.

0 commit comments

Comments
 (0)