Jora

1.0.0-beta.15 · active · verified Sun Apr 19

Jora is a JavaScript object query engine and language for processing and querying JSON-like data structures efficiently. While currently in a beta development phase (v1.0.0-beta.15), it is considered stable, though its syntax might undergo changes in future releases. The project maintains a relatively frequent release cadence for beta versions, actively introducing new features, improvements, and addressing issues. Jora distinguishes itself with a compact, JavaScript-like syntax for common data manipulation tasks, tolerant query execution that simply returns nothing for unreachable paths instead of throwing errors, and automatic aggregation and deduplication of values. It also includes advanced features like a stat collecting mode for powering suggestions in editors and an extensible Domain Specific Language (DSL) via custom methods and assertions, making it highly adaptable for complex data transformations. It is a core component within the Discovery.js ecosystem, used for data visualization and building interactive reports.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates defining global custom methods and assertions using `setup`, then compiling and executing a Jora query that filters data, uses the custom functions, and aggregates results.

import jora, { setup } from 'jora';

// Setup custom methods and assertions globally (optional)
setup({
  methods: {
    addOne: (value) => value + 1,
    sumAll: (arr) => arr.reduce((acc, current) => acc + current, 0),
  },
  assertions: {
    isPositive: (value) => value > 0,
    hasTag: (value, tag) => Array.isArray(value) && value.includes(tag),
  }
});

const data = [
  { id: 1, name: 'Apple', price: 1.2, tags: ['fruit', 'sweet'] },
  { id: 2, name: 'Banana', price: 0.8, tags: ['fruit'] },
  { id: 3, name: 'Carrot', price: 0.5, tags: ['vegetable', 'root'] },
  { id: 4, name: 'Milk', price: 2.5, tags: ['dairy', 'drink'] },
  { id: 5, name: 'Orange', price: 1.5, tags: ['fruit', 'citrus'] }
];

// Compile a query using custom methods and assertions
const query = jora(`
  .[tags.hasTag('fruit') and price.isPositive()] | {
    count: count(),
    avgPrice: avg(price),
    names: name.addOne()
  }
`);

// Execute the compiled query against the data
const result = query(data);
console.log(JSON.stringify(result, null, 2));

/*
Expected output:
{
  "count": 3,
  "avgPrice": 1.1666666666666667,
  "names": [
    "Apple1",
    "Banana1",
    "Orange1"
  ]
}
*/

view raw JSON →