kellyjonbrazil /
jc
CLI tool and python library that converts the output of popular command-line tools, file-types, and common strings to JSON, YAML, or Dictionaries. This allows piping of output to tools like jq and simplifying automation scripts.
Loading repository data…
kellyjonbrazil / repository
CLI tool to filter JSON and JSON Lines data with Python syntax. (Similar to jq)
Built on
jello:
- Jello Explorer (aka
jellex) interactive TUIjelloweb demo
Filter JSON and JSON Lines data with Python syntax
jello is similar to jq in that it processes JSON and JSON Lines data except jello uses standard python dict and list syntax.
JSON or JSON Lines can be piped into jello via STDIN or can be loaded from a JSON file or JSON Lines files (JSON Lines are automatically slurped into a list of dictionaries). Once loaded, the data is available as a python list or dictionary object named '_'. Processed data can be output as JSON, JSON Lines, bash array lines, or a grep-able schema.
For more information on the motivations for this project, see my blog post.
You can install jello via pip, via OS Package Repository, MSI installer for Windows, or by downloading the correct binary for your architecture and running it anywhere on your filesystem.
For the most up-to-date version and the most cross-platform option, use pip or pip3 to download and install jello directly from PyPi:
pip3 install jello
| OS | Command |
|---|---|
| Debian/Ubuntu linux | apt-get install jello |
| Fedora linux | dnf install jello |
| Arch linux | pacman -S jello |
| macOS | brew install jello |
For more OS packages, see https://repology.org/project/jello/versions.
See Releases on Github for MSI packages and binaries.
cat data.json | jello [OPTIONS] [QUERY | -q <query_file>]
jello [OPTIONS] [QUERY | -q <query_file>] [-f <input_files>]
QUERY is optional and can be most any valid python code. Alternatively, a
query file can be specified with -q to load the query from a file. Within the query, _ is the sanitized JSON from STDIN presented as a python dict or list of dicts. If QUERY is omitted then the original JSON input will simply be pretty printed. You can use dot notation or traditional python bracket notation to access key names.
Note: Reserved key names that cannot be accessed using dot notation can be accessed via standard python dictionary notation. (e.g.
_.foo["get"]instead of_.foo.get)
A simple query:
cat data.json | jello _.foo
or
jello _.foo -f data.json
or
jello '_["foo"]' -f data.json
-c compact print JSON output instead of pretty printing-C force color output even when using pipes (overrides -m and the NO_COLOR env variable)-e empty data (don't process data from STDIN or file)-f load input data from JSON file or JSON Lines files (must be the final option, if used)-i initialize environment with a custom config file-l lines output (suitable for bash array assignment)-m monochrome output-n print selected null values-q load query from a file-r raw output of selected strings (no quotes)-R raw string input (don't auto convert input to dict/list)-s print the JSON schema in grep-able format-t print type annotations in schema view-h help-v version infojello simply pretty prints the JSON if there are no options or query passed:
echo '{"foo":"bar","baz":[1,2,3]}' | jello
{
"foo": "bar",
"baz": [
1,
2,
3
]
}
If you prefer compact output, use the -c option:
echo '{"foo":"bar","baz":[1,2,3]}' | jello -c
{"foo":"bar","baz":[1,2,3]}
Use the -l option to convert lists/arrays into lines:
echo '{"foo":"bar","baz":[1,2,3]}' | jello -l _.baz
1
2
3
The -l option also allows you to create JSON Lines:
echo '[{"foo":"bar","baz":[1,2,3]},{"fiz":"boo","buz":[4,5,6]}]' | jello -l
{"foo":"bar","baz":[1,2,3]}
{"fiz":"boo","buz":[4,5,6]}
You can print a grep-able schema by using the -s option:
echo '{"foo":"bar","baz":[1,2,3]}' | jello -s
_ = {};
_.foo = "bar";
_.baz = [];
_.baz[0] = 1;
_.baz[1] = 2;
_.baz[2] = 3;
Use the -l option to print JSON array output in a manner suitable to be assigned to a bash array. The -r option can be used to remove quotation marks around strings. If you want null values to be printed as null, use the -n option, otherwise they are printed as blank lines.
Bash variable:
variable=($(cat data.json | jello -rl _.foo))
Bash array variable (Bash 4+):
mapfile -t variable < <(cat data.json | jello -rl _.foo)
Bash array variable (older versions of Bash):
variable=()
while read -r value; do
variable+=("$value")
done < <(cat data.json | jello -rl _.foo)
You can work with other types of data with the -R (raw string input) option. For example,
if you would like to read in YAML data you can load the data as a raw string, import
the yaml library, and load the string data into _ with the yaml library:
$ cat values.yaml
var1: value1
var2: value2
var3: value3
$ jello -Rr '
import yaml
_ = yaml.safe_load(_)
_["var2"]
' -f values.yaml
value2
Note: Dot notation is not supported with the
-Roption unless the library used to convert the raw string supports this. (e.g.python-benedict)
Custom colors can be set via the JELLO_COLORS environment variable. Any colors set in the environment variable will take precedence over any colors set in the initialization file. (see Advanced Usage)
The JELLO_COLORS environment variable takes four comma separated string values in the following format:
JELLO_COLORS=<keyname_color>,<keyword_color>,<number_color>,<string_color>
Where colors are: black, red, green, yellow, blue, magenta, cyan, gray, brightblack, brightred, brightgreen, brightyellow, brightblue, brightmagenta, brightcyan, white, or default
For example, to set to the default colors:
JELLO_COLORS=blue,brightblack,magenta,green
or
JELLO_COLORS=default,default,default,default
You can set the NO_COLOR environment variable to any value to disable color output in jello. Note that using the -C option to force color output will override both the NO_COLOR environment variable and the -m option.
Here is more Advanced Usage information.
To accelerate filter development and testing, try
jellex.jellexis an interactive front-end TUI built onjellothat allows you to see your filter results in real-time along with any errors.
$ jc -a | jello -s
_ = {};
_.name = "jc";
_.version = "1.17.2";
_.description = "JSON CLI output utility";
_.author = "Kelly Brazil";
_.author_email = "kellyjonbrazil@gmail.com";
_.website = "https://github.com/kellyjonbrazil/jc";
_.copyright = "© 2019-2021 Kelly Brazil";
_.license = "MIT License";
_.parser_count = 80;
_.parsers = [];
_.parsers[0] = {};
_.parsers[0].name = "acpi";
_.parsers[0].argument = "--acpi";
_.parsers[0].version = "1.2";
_.parsers[0].description = "`acpi` command parser";
_.parsers[0].author = "Kelly Brazil";
_.parsers[0].author_email = "kellyjonbrazil@gmail.com";
_.parsers[0].compatible = [];
_.parsers[0].compatible[0] = "linux";
_.parsers[0].magic_commands = [];
_.parsers[0].magic_commands[0] = "acpi";
_.parsers[1] = {};
_.parsers[1].name = "airport";
_.parsers[1].argument = "--airport";
_.parsers[1].version = "1.3";
...
jc dig example.com | jello -st
_ = []; // (array)
_[0] = {}; // (object)
_[0].id = 23819; // (number)
_[0].opcode = "QUERY"; // (string)
_[0].status = "NOERROR"; // (string)
_[0].flags = []; // (array)
_[0].flags[0] = "qr"; // (string)
_[0].flags[1] = "rd"; // (string)
_[0].flags[2] = "ra"; // (string)
_[0].query_num = 1; // (number)
_[0].answer_num = 1; // (number)
_[0].authority_num = 0; // (number)
_[0].additional_num = 1; // (number)
_[0].opt_pseudosection = {}; // (object)
_[0].opt_pseudosection.edns = {}; // (object)
_[0].opt_pseudosection.edns.version = 0; // (number)
_[0].opt_pseudosection.edns.flags = []; // (array)
_[0].opt_pseudosection.edns.udp = 4096; // (number)
_[0].question = {}; // (object)
_[0].question.name = "example.com."; // (string)
_[0].question.class = "IN"; // (string)
_[0].question.type = "A"; // (string)
_[0].answer = []; // (array)
_[0].answer[0] = {}; // (object)
_[0].answer[0].name = "example.com."; // (string)
_[0].answer[0].class = "IN"; // (string)
_[0].answer[0].type = "A"; // (string)
_[0].answer[0].ttl = 48358; // (number)
_[0].answer[0].data = "93.184.216.34"; // (string)
_[0].query_time = 46; // (number)
_[0].server = "2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)"; // (string)
_[0].when = "Mon Nov 29 09:41:11 PST 2021"; // (string)
_[0].rcvd = 56; // (number)
_[0].when_epoch = 1638207671; // (number)
_[0].when_epoch_utc = null; // (null)
jc dig example.com | jello -st | grep '(object)\|(array)'
_ = []; // (array)
_[0] = {}; // (object)
_[0].flags = []; // (array)
_[0].opt_pseudosection = {}; // (object)
_[0].opt_pseudosection.edns = {}; // (object)
_[0].opt_pseudosection.edns.flags = []; // (array)
_[0].question = {}; // (object)
_[0].answer = []; //
Selected from shared topics, language and repository description—not editorial ratings.
kellyjonbrazil /
CLI tool and python library that converts the output of popular command-line tools, file-types, and common strings to JSON, YAML, or Dictionaries. This allows piping of output to tools like jq and simplifying automation scripts.
BillGatesCat /
yf is a CLI tool that allows for quick and easy access to Yahoo! Finance market data.
jrzvnn /
Taskmaster-CLI is a command-line tool for managing a to-do list.
maundergit /
command line tools to handle CSV(Comma Separated Value) file by python and bash script
DisabledAbel /
This project lets you easily transform plain text instructions into executable Bash scripts. Perfect for developers, sysadmins, or anyone who wants to automate tasks quickly without writing Bash manually. Includes a modern “Open Application” button to launch the tool directly.
JoshLinneburg /
Shared collection of CLI utilities — bash scripts, git subcommands, python tools, whatever's useful. Works on Linux, macOS, and Windows.