#json #cli #json-path #utility

app cj

Blazing fast command-line json processor

2 releases

0.0.2 Jul 2, 2022
0.0.1 Jul 2, 2022
0.0.0 Jun 27, 2022

#1694 in Command line utilities


92 lines


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


cj 0.1.0

    cj [OPTIONS] [--] [STDIN]

    <STDIN>    read from stdin

    -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


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.


~143K SLoC