Socket
Socket
Sign inDemoInstall

jsonata

Package Overview
Dependencies
0
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonata


Version published
Maintainers
1
Created

Package description

What is jsonata?

jsonata is a lightweight query and transformation language for JSON data. It allows you to query, transform, and manipulate JSON data with a simple and expressive syntax.

What are jsonata's main functionalities?

Querying JSON Data

This feature allows you to query JSON data using a simple and expressive syntax. In this example, we query for a person named 'John' in the 'people' array.

const jsonata = require('jsonata');
const data = { "people": [{ "name": "John", "age": 30 }, { "name": "Jane", "age": 25 }] };
const expression = jsonata('people[name="John"]');
const result = expression.evaluate(data);
console.log(result); // Output: { "name": "John", "age": 30 }

Transforming JSON Data

This feature allows you to transform JSON data into a new structure. In this example, we transform the 'people' array to have 'fullName' and 'yearsOld' properties instead of 'name' and 'age'.

const jsonata = require('jsonata');
const data = { "people": [{ "name": "John", "age": 30 }, { "name": "Jane", "age": 25 }] };
const expression = jsonata('people.{"fullName": name, "yearsOld": age}');
const result = expression.evaluate(data);
console.log(result); // Output: [{ "fullName": "John", "yearsOld": 30 }, { "fullName": "Jane", "yearsOld": 25 }]

Aggregating JSON Data

This feature allows you to perform aggregations on JSON data. In this example, we calculate the sum of ages in the 'people' array.

const jsonata = require('jsonata');
const data = { "people": [{ "name": "John", "age": 30 }, { "name": "Jane", "age": 25 }] };
const expression = jsonata('people.age.sum()');
const result = expression.evaluate(data);
console.log(result); // Output: 55

Other packages similar to jsonata

Changelog

Source

1.8.3 Maintenance Release

  • Remove incomplete polyfill for Array.from() (issue #432)
  • Fix $not to return empty sequence for missing inputs (issue #433)
  • Fix RangeError (stack overflow) when querying very large objects (issue #434)

Readme

Source

JSONata

JSON query and transformation language

NPM statistics

Build Status Coverage Status

Reference implementation of the JSONata query and transformation language.

Installation

  • npm install jsonata

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.

Keywords

FAQs

Last updated on 22 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc