Crates.io | cj |
lib.rs | cj |
version | 0.0.2 |
source | src |
created_at | 2022-06-27 22:06:00.797538 |
updated_at | 2022-07-02 14:59:38.394183 |
description | Blazing fast command-line json processor |
homepage | https://github.com/ovuncyayla/cj |
repository | https://github.com/ovuncyayla/cj |
max_upload_size | |
id | 614385 |
size | 22,699 |
cj is a lightweight command-line tool to process JSON files blazingly fast.
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
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.