/jsonni-cli

Transform data on command line

Primary LanguageTypeScript

JSONNI JSONNI

Sponsored

Manipulate data with ES6, Lodash or fromfrom, on command line.

Command line version of JSONNI

Install

npm install -g jsonni-cli

Features

  • Reads data from stdin
  • Supports different syntaxes for querying data
    • ES
    • Lodash
    • fromfrom
  • Supports multiple output formats
    • JSON
    • CSV
    • TSV
  • Customizable output indentation
  • Optionally minimized output JSON

Usage

Usage: jsonni [options]

Options:
  -v, --version                   output the version number
  -m --minify                     minify output
  -q --query <query>              query to transform data with
  --input <format>                input format. Available formats: json, tsv, csv
  --input-header <header>         input CSV/TSV headers. Separated with ","
  --input-delimiter <delimiter>   CSV/TSV input delimiter character. Defaults to ","
  --output <format>               output format. Available formats: json, tsv, csv
  --output-delimiter <delimiter>  CSV/TSV output delimiter character. Defaults to ","
  --indent <indent>               output indentation, defaults to "  "
  -h, --help                      output usage information

About -q parameter

Parameter value should be quoted with single quotes (') instead of double (").

Examples

curl --silent http://jsonplaceholder.typicode.com/todos?_limit=5 | jsonni

default.png

Grab first item

curl --silent http://jsonplaceholder.typicode.com/todos?_limit=5 | jsonni -q '$input[0]'

json_es_first.png

Filter

curl --silent http://jsonplaceholder.typicode.com/todos?_limit=5 | jsonni -q '$input.filter(item => item.completed)'

json_es_filter.png

Lodash, with chain

curl --silent http://jsonplaceholder.typicode.com/todos?_limit=5 | jsonni -q '_.chain($input).orderBy(["title"], ["asc"]).map("title")'

json_lodash_chain.png

Lodash, without chain

curl --silent http://jsonplaceholder.typicode.com/todos?_limit=5 | jsonni -q '_.map(_.orderBy($input, ["title"], ["asc"]), "title")'

json_lodash.png

fromfrom

curl --silent http://jsonplaceholder.typicode.com/todos?_limit=5 | jsonni -q 'from($input).filter(item => item.title.startsWith("fugiat")).toArray()'

fromfrom.png

JSON, with custom indentation

curl --silent http://jsonplaceholder.typicode.com/todos?_limit=5 | jsonni -q '$input[0]' --indent="\t"

json_custom_indent.png

JSON to CSV

curl --silent http://jsonplaceholder.typicode.com/todos?_limit=5 | jsonni -q '$input[0]' --output=csv --output-delimiter=";"

json_to_csv.png

JSON to TSV

curl --silent http://jsonplaceholder.typicode.com/todos?_limit=5 | jsonni -q '$input[0]' --output=tsv

json_to_tsv.png

CSV to JSON

cat csv.csv | jsonni -q '$input[0]' --input=csv

csv_to_json.png

CSV to CSV

cat csv.csv | jsonni -q '$input.filter(user => user.isActive)' --input=csv --output=csv

csv_to_csv.png

CSV to TSV

cat csv.csv | jsonni -q '$input.filter(user => user.isActive)' --input=csv --output=tsv

csv_to_tsv.png

CSV without headers

cat csvWithoutHeaders.csv | jsonni -q '$input[0]' --input=csv --input-header=id,isActive,age,name,registered

csv_without_headers.png

Acknowledgements

This project is a grateful recipient of the Futurice Open Source sponsorship program.

Icon made by Freepik from www.flaticon.com

License

MIT