@vibl/jsonata
TypeScript icon, indicating that this package has built-in type declarations

1.7.2 • Public • Published

JSONata with COW cloning for the Transform operator

This package is forked from https://github.com/jsonata-js/jsonata.

In the original JSONata package, the Transform operator (... ~> | ... | ... |) deep clones the input object, which can be very costly in memory, in GC resources and in deep equality checking afterwards (e.g. for React components with a Redux store transformed with JSONata in reducers).

In this package, the Transform operator does copy-on-write cloning, which means it only clones the "lineage" of the transformed values (i.e. the parents of the transformed values, up to the root input object). It does not mutate any object in the process.

Caveats:

  • It does NOT work when the location pattern includes a descendant (**) operator.
  • The head part (before the ~>) should only be $, i.e. the root element. So, the whole expression should always start with jsonata("$ ~> |....

Installation

  • npm install @vibl/jsonata

Below is the original README of the JSONata package:

JSONata

JSON query and transformation language

NPM statistics

Build Status Coverage Status

Reference implementation of the JSONata query and transformation language.

Quick start

In Node.js:

var jsonata = require("jsonata");

var data = {
  example: [
    {value: 4},
    {value: 7},
    {value: 13}
  ]
};
var expression = jsonata("$sum(example.value)");
var result = 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>
      function greeting() {
        var json = JSON.parse(document.getElementById('json').value);
        var result = 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

Contributing

See the CONTRIBUTING.md for details of how to contribute to this repo.

Package Sidebar

Install

npm i @vibl/jsonata

Homepage

jsonata.org/

Weekly Downloads

0

Version

1.7.2

License

MIT

Unpacked Size

789 kB

Total Files

9

Last publish

Collaborators

  • vianneystroebel