Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Changelog
1.0.0-beta.10 (December 6, 2023)
$arg => expr
and ($a, $b) => expr
forms to be supportedthis
in custom methods and assertions defined as functions to include a context
reference to the query context. Additionally, introduced this.method(name, ...args)
and this.assertion(name, ...args)
methods to call a custom method or use an assertion.$$
and #
in custom methods and assertions defined as strings (Jora queries).| expr
is now a valid query$
was used as an object entry, e.g. { $, prop: 1 }
pick()
method when used with a function to apply bool()
to the result of the functionReadme
JavaScript object query language, and a library to process and perform Jora queries on data.
STATUS: Jora is stable, but syntax may change in next releases. Still very much work in progress (ideas and thoughts).
Features:
Related projects:
Table of content:
Jora is a query language designed for JSON-like data structures. It extends JSON5 and shares many similarities with JavaScript.
See Docs & playground.
// single-line comment
/* multi-line
comment */
Jora expressions are the building blocks of Jora queries. Expressions can include comments, literals, operators, functions, and variables.
Jora supports literals, which include:
42
, -3.14
, 6.022e23
"hello"
, 'world'
, \
template${yes}`,
"\u{1F600}"`true
, false
/regexp/flags
{ hello: 'world' }
(see Object literals)[1, 2, 3]
(see Array literals)=> …
(see Functions)NaN
, Infinity
, null
and undefined
See Literals
Jora supports most JavaScript operators, including:
+
, -
, *
, /
, %
=
, !=
, <
, <=
, >
, >=
, ~=
and
, or
, not
(alias no
), ??
, is
, in
, not in
, has
, has no
?:
( )
|
See Operators
Jora provides notations for accessing properties and elements: dot, bracket and slice notations. Dot notation is similar to JavaScript's property access notation, using a period followed by the property name (e.g., $.propertyName
). Bracket notation encloses the property name or index within square brackets (e.g., $['propertyName']
or $[0]
), it's also possible to use functions to choose. Slice notation provides a concise syntax to slice elements with optional step (array[5:10:2]
selects each odd element from 5th to 10th indecies).
Jora provides a rich set of built-in methods for manipulating data, such as map()
, filter()
, group()
, sort()
, reduce()
, and many others. You can also define custom functions using the =>
arrow function syntax, and use them as a method.
group()
methodsort()
methodJora has a concise syntax for mapping and filtering. The map(fn)
method is equivalent to .(fn())
, while the filter(fn)
method is equivalent to .[fn()]
.
.[…]
and filter()
method.(…)
and map()
method..(…)
Variables in Jora are helpful for storing intermediate results or simplifying complex expressions. To define a variable, use the $variableName: expression;
syntax.
See Variables
Install with npm:
npm install jora
Basic usage:
// ESM
import jora from 'jora';
// CommonJS
const jora = require('jora');
Bundles are available for use in a browser:
dist/jora.js
– minified IIFE with jora
as global<script src="node_modules/jora/dist/jora.js"></script>
<script>
jora('query')(data, context);
</script>
dist/jora.esm.js
– minified ES module<script type="module">
import jora from 'node_modules/jora/dist/jora.esm.js'
// ...
</script>
By default (for short path) a ESM version is exposing. For IIFE version a full path to a bundle should be specified. One of CDN services like unpkg
or jsDelivr
can be used:
jsDeliver
<!-- ESM -->
<script type="module">
import jora from 'https://cdn.jsdelivr.net/npm/jora';
</script>
<!-- IIFE with an export `jora` to global -->
<script src="https://cdn.jsdelivr.net/npm/jora/dist/jora.js"></script>
unpkg
<!-- ESM -->
<script type="module">
import jora from 'https://unpkg.com/jora';
</script>
<!-- IIFE with an export `jora` to global -->
<script src="https://unpkg.com/jora/dist/jora.js"></script>
import jora from 'jora';
// create a query
const query = jora('foo.bar');
// perform a query
const result = query(data, context);
See the details in Jora library API
Get npm dependency paths (as a tree) that have packages with more than one version:
import jora from 'jora';
import { exec } from 'child_process';
function printTree() {
// see implementation in examples/npm-ls.js
}
exec('npm ls --all --json', (error, stdout) => {
if (error) {
return;
}
const npmTree = JSON.parse(stdout);
const depsPathsToMultipleVersionPackages = jora(`
$normalizedDeps: => dependencies.entries().({ name: key, ...value });
$multiVersionPackages:
..$normalizedDeps()
.group(=>name, =>version)
.({ name: key, versions: value.sort() })
.[versions.size() > 1];
$pathToMultiVersionPackages: => .($name; {
name,
version,
otherVersions: $multiVersionPackages[=>name=$name].versions - version,
dependencies: $normalizedDeps()
.$pathToMultiVersionPackages()
.[name in $multiVersionPackages.name or dependencies]
});
$pathToMultiVersionPackages()
`)(npmTree);
printTree(depsPathsToMultipleVersionPackages);
});
Example of output:
jora@1.0.0
├─ c8@7.11.0
│ ├─ istanbul-lib-report@3.0.0
│ │ └─ supports-color@7.2.0 [more versions: 8.1.1]
│ ├─ test-exclude@6.0.0
│ │ └─ minimatch@3.1.2 [more versions: 3.0.4]
│ ├─ v8-to-istanbul@8.1.1
│ │ └─ convert-source-map@1.8.0
│ │ └─ safe-buffer@5.1.2 [more versions: 5.2.1]
│ ├─ yargs-parser@20.2.9 [more versions: 20.2.4]
│ └─ yargs@16.2.0
│ └─ yargs-parser@20.2.9 [more versions: 20.2.4]
├─ eslint@8.10.0
│ ├─ @eslint/eslintrc@1.2.0
│ │ ├─ ignore@4.0.6 [more versions: 5.2.0]
│ │ └─ minimatch@3.1.2 [more versions: 3.0.4]
...
See more examples in Complex Jora query examples
FAQs
JavaScript object query engine
The npm package jora receives a total of 93,984 weekly downloads. As such, jora popularity was classified as popular.
We found that jora demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.