The repository is a fork of the original JSONata for adaptation in DocHub.
npm install dochub-jsonata
In Node.js:
const jsonata = require('dochub-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
})()
To ensure the effective and user-friendly utilization of JSONata as a query language for the architectural repository data lake, we found it necessary to enhance its basic functionality with several new features.
The debugger allows for step-by-step execution of query commands, enabling users to monitor the results of their execution.
const expression = jsonata(`(
$a := 1;
$sum(example.value);
$a := function() {(
2;
3;
4;
)};
debugger; /* Calls a debug function */
$a();
$eval('(5;6;7)');
8;
9;
10;
)`);
const result = await expression.evaluate(data, undefined, undefined, async(context) => {
console.info(context);
return 'next'; // The debug function must return one of the values: run / into / next
});
Result:
{$: {…}, step: {…}, input: {…}, environment: {…}}
{$: 4, step: {…}, input: {…}, environment: {…}}
{$: 7, step: {…}, input: {…}, environment: {…}}
{$: 8, step: {…}, input: {…}, environment: {…}}
{$: 9, step: {…}, input: {…}, environment: {…}}
{$: 10, step: {…}, input: {…}, environment: {…}}
10
- JSONata documentation
- DocHub