This repository is a fork of the JSONata project. It applies a patch to the current JSONata version to undo a change made blocking access to object prototype properties. This broke certain behaviours that Node-RED flows made use of. The code still blocks access to the prototype, to prevent pollution, but allows access to other properties in the chain.
We will endeavour to keep this fork in sync with upstream as needed.
JSON query and transformation language
Reference implementation of the JSONata query and transformation language.
npm install jsonata
In Node.js:
const jsonata = require('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>- JSONata documentation
- JavaScript API
- Intro talk at London Node User Group
See the CONTRIBUTING.md for details of how to contribute to this repo.