@ambivio/jsonata
v2.1.0-ambivio.1
Published
JSON query and transformation language (Ambivio fork of jsonata with the ?: elvis-operator array-predicate fix; see jsonata-js/jsonata#780)
Maintainers
Readme
@ambivio/jsonata
Ambivio fork of jsonata — a drop-in replacement that ships an extra bug-fix:
- Fix: the
?:(elvis/default) operator returned the wrong value when the LHS contained an array predicate (e.g.[true][-1] ?: "no",array[1] ?: "no") or a negative numeric literal (e.g.-5 ?: 99). Upstream PR: jsonata-js/jsonata#780.Once the upstream PR is merged and released, prefer the official
jsonatapackage.
JSON query and transformation language
Reference implementation of the JSONata query and transformation language.
Installation
npm install @ambivio/jsonata
Quick start
In Node.js:
const jsonata = require('@ambivio/jsonata');
const data = {
example: [
{value: 4},
{value: 7},
{value: 13}
]
};
(async () => {
const expression = jsonata('$sum(example.value)');
const result = await expression.evaluate(data); // returns 24
})()In a browser:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JSONata test</title>
<script src="https://cdn.jsdelivr.net/npm/jsonata/jsonata.min.js"></script>
<script>
async function greeting() {
var json = JSON.parse(document.getElementById('json').value);
var result = await jsonata('"Hello, " & name').evaluate(json);
document.getElementById('greeting').innerHTML = result;
}
</script>
</head>
<body>
<textarea id="json">{ "name": "Wilbur" }</textarea>
<button onclick="greeting()">Click me</button>
<p id="greeting"></p>
</body>
</html>More information
- JSONata documentation
- JavaScript API
- Intro talk at London Node User Group
Contributing
See the CONTRIBUTING.md for details of how to contribute to this repo.
