Détail du package

jora-cli

discoveryjs64MIT2.1.0

Command line interface for Jora

cli, jora, query, json

readme

jora-cli

NPM version Build Status Coverage Status

Command line interface for Jora (a JSON query language)

jora-cli-demo

Install

npm i -g jora-cli

Usage

> jora -h
Usage:

    jora [query] [options]

Options:

        --no-color               Suppress color output
    -c, --compression [name]     Compress output: gzip (default when [name] is omitted), deflate
        --dry-run                Don't output result, only report what it would have done (enables --verbose mode)
    -e, --encoding <encoding>    Output encoding: json (default), jsonxl (snapshot9)
    -f, --force                  Force overwriting output file
    -h, --help                   Output usage information
    -i, --input <filename>       Input file
    -o, --output <filename>      Output file (outputs to stdout if not set)
    -p, --pretty [indent]        Pretty-prints output with specified indentation (4 spaces if [indent] is omitted)
    -q, --query <query>          Jora query or path to a query file with extension .jora
        --verbose                Output debug info about actions
    -v, --version                Output version

Examples

  • Get a single field from, e.g. "version":

    jora <package.json version
  • Get all top level dependencies count:

    jora -i package.json -q '(dependencies.keys() + devDependencies.keys()).size()'
  • Find packages with more than a single version (run query from a file)

    npm ls --json | jora find-multi-version-packages.jora

    The content of find-multi-version-packages.jora may be as follows:

    ..(dependencies.entries().({ name: key, ...value }))
        .group(=>name, =>version)
        .({ name: key, versions: value })
        .[versions.size() > 1]
  • Supported queries from JSONXL, and conversion JSON ⇄ JSONXL.

    Note: JSONXL is a binary replacement for JSON. It is supported by any app built on Discovery.js, including JsonDiscovery, CPUpro and Statoscope. JSONXL not only saves space and transfer time but also offers faster decoding and a lower memory footprint, which is beneficial for processing large datasets.

    • Queries for JSONXL input work the same ways as for JSON:
      jora <input.jsonxl "select.something"
    • Convert JSON into JSONXL:
      jora <input.json >output.jsonxl -e jsonxl
    • Convert JSONXL into JSON
      jora <input.jsonxl >output.json
  • Supported gzip and deflate as input and output

    jora-cli can read gzip/deflate on input (auto-detected) and write compressed output via --compression (-c).

    • Input compression is detected automatically for both stdin and -i <file>.
    • --compression (-c) affects output only; omit the name to default to gzip.
    • Compression is applied after encoding/pretty-printing.
    • Choose an appropriate extension for compressed files (e.g. .json.gz, .jsonxl.gz, .deflate).
    • Reading compressed input (auto-detected for gzip and deflate, works for files and stdin):

      # query a gzipped JSON
      jora < data.json.gz "stats.total"
      
      # query a deflated JSON (raw deflate stream)
      jora -i data.json.deflate "items.size()"
      
      # pipe from cat/gunzip as well
      cat data.json.gz | jora "select.deep.field"
    • Writing compressed output using -c, --compression:

      # gzip-compress output (default when name is omitted)
      jora -i data.json -q "items.group(=>type)" -c > result.json.gz
      
      # explicitly choose deflate
      jora < data.json "items.pick(=>active)" -c deflate > result.json.deflate
    • Mixing with JSONXL encoding:

        # convert JSON -> JSONXL and gzip the result (most compact output combo)
        jora < data.json > data.jsonxl.gz -e jsonxl -c
      
        # read gzipped JSON, query, and write gzipped JSONXL in one go
        jora < data.json.gz -q "heavy.[score > 0.9]" -e jsonxl -c > filtered.jsonxl.gz
      
        # convert JSONXL -> JSON while keeping compression on output
        jora < data.jsonxl -e json -c > data.json.gz

Caveats

jora-cli takes a valid JSON and produce a valid JSON as a result. However, jora language could produce some values that incompatable with JSON, such values are transforming:

  • NaN, Infinity and -Infinity are converting to null, that's a behaviour of JSON.stringify()
  • undefined
    • is convering to null when a result of query (top level) or an element of an array
    • object entries with undefined as a value are eliminating

License

MIT

changelog

2.1.0 (August 16, 2025)

  • Added gzip and deflate compression support for input data, i.e. compressed JSON or JSONXL is now consumed seamlessly
  • Added --compression [type] (-c [type]) option to specify output compression (gzip or deflate). When the type is not specified, gzip is used. For example, jora -c -e jsonxl will output gzipped JSONXL (the most compact output size combo).
  • Updated JSONXL:
    • Fixed an edge case for signed numbers in the range ±[MAX_SAFE_INTEGER/2 … MAX_SAFE_INTEGER].
    • Removed the limitation that could trigger when the total encoded string length exceeded the maximum string length (~500 MB in V8)
  • Fixed output progress display for JSONXL

2.0.3 (July 10, 2025)

  • Fixed an exception when running jora -v

2.0.2 (July 10, 2025)

2.0.1 (February 6, 2025)

  • Fixed missed package files

2.0.0 (February 6, 2025)

  • Bumped jora to 1.0.0-beta.13
  • Added support for JSONXL (snapshot9) as input encoding
  • Added --encoding option to specify output encoding, supported JSON and JSONXL
  • Added --force option to enforce overwritting a file
  • Added --dry-run option
  • Added --verbose option
  • Extended the --query option to accept a file path containing a Jora query, the file must have a .jora extension
  • Changed behavior for writing to an existing file specified with the --output option. The operation now fails unless the --force option is used
  • Removed --sandbox option (until re-implemented)

1.5.1 (July 29, 2021)

  • Bumped jora-sandbox to 1.3.0

1.5.0 (November 12, 2020)

  • Bumped jora to 1.0.0-beta.5

1.4.0 (May 20, 2020)

  • Bumped jora to 1.0.0-beta.2
  • Bumped jora-sandbox to 1.2.1

1.3.0 (December 17, 2019)

  • Bumped jora to 1.0.0-alpha.11
  • Bumped jora-sandbox to 1.1.0

1.2.0 (September 19, 2019)

  • Added --sandbox option to open data and query in sandbox (opens in a browser a web interface with injected data and query saved in a temporary file)

1.1.1 (August 21, 2019)

  • Fixed missed files in package

1.1.0 (August 22, 2019)

  • Added output highlighting when appropriate. Use --no-color option to suppress color output (#2)
  • Fixed output of undefined value

1.0.1 (July 4, 2019)

  • Used dist version of jora to reduce startup time (up to 10x times)
  • Removed wrongly added dependency
  • Fixed command name in help info
  • Fixed returning undefined when no query, now command returns input itself as when query is empty string

1.0.0 (July 4, 2019)

  • Initial release