cj

Crates.iocj
lib.rscj
version0.0.2
sourcesrc
created_at2022-06-27 22:06:00.797538
updated_at2022-07-02 14:59:38.394183
descriptionBlazing fast command-line json processor
homepagehttps://github.com/ovuncyayla/cj
repositoryhttps://github.com/ovuncyayla/cj
max_upload_size
id614385
size22,699
Övünç Yayla (ovuncyayla)

documentation

README

CJ

cj is a lightweight command-line tool to process JSON files blazingly fast.

Usage

cj 0.1.0

USAGE:
    cj [OPTIONS] [--] [STDIN]

ARGS:
    <STDIN>    read from stdin

OPTIONS:
    -c, --compress                compress JSON input
    -f, --filters <FILTERS>...    filters
    -h, --help                    Print help information
    -p, --path [<PATH>...]        file path relative or absolute
    -V, --version                 Print version information

Examples

Assuming that you have test.json file in cwd with the following content, when no filter expression is given the default behaviour is pretty printing the json input. (Coloring support is coming soon...).

$ cat test.json | cj
# OR you can specify the absolute / relative file path with -p option
$ cj -p test.json
{
  "store": {
    "bicycle": {
      "color": "red",
      "price": 19.95
    },
    "book": [
      {
        "author": "Nigel Rees",
        "category": "reference",
        "price": 8.95,
        "title": "Sayings of the Century"
      },
      {
        "author": "Evelyn Waugh",
        "category": "fiction",
        "price": 12.99,
        "title": "Sword of Honour"
      },
      {
        "author": "Herman Melville",
        "category": "fiction",
        "isbn": "0-553-21311-3",
        "price": 8.99,
        "title": "Moby Dick"
      },
      {
        "author": "J. R. R. Tolkien",
        "category": "fiction",
        "isbn": "0-395-19395-8",
        "price": 22.99,
        "title": "The Lord of the Rings"
      }
    ]
  }
}

Filter books which costs lesser than 10:

$ cj -f $.store.book\[\?\(\@.price\ \<\ 10\)\].title 

# Outputs the following:
# "Sayings of the Century","Moby Dick"

You can also chain the filters:

$ cj -f '$.store.book[?(@.price < 10)].title' $..price

# Outputs the following:
# "Sayings of the Century","Moby Dick"
# 19.95,8.95,12.99,8.99,22.99

You can find more information about json path expressions here.

Commit count: 16

cargo fmt