jc
Converts output of CLI tools, file types, and strings to JSON or Python dictionaries so it can be piped to jq and used in scripts.
jc (JSON Convert) is a command-line tool and Python library that parses the output of many CLI commands, file types, and common strings into JSON. It reads from STDIN and writes JSON to STDOUT, so output from commands like dig can be piped into jq or jello. For example, dig example.com | jc --dig | jq -r '.[].answer[].data' returns the answer IP address. Supported commands, file types, and strings are listed in the Parsers section of the README.
There are two invocation styles. The pipe style takes a parser flag: COMMAND | jc [SLICE] [OPTIONS] PARSER, and also works with cat FILE or echo STRING. The "magic" syntax puts jc in front of the command, as in jc dig example.com, and also accepts /proc file paths. Command aliases and shell builtins are not supported in magic syntax. Output is compact JSON by default, and -p pretty-prints it.
By default each parser follows a strict schema. Known numbers are converted to int/float, known booleans and null values are converted, and some parsers add semantic context fields. The -r option, or raw=True in the Python API, returns the raw, pre-processed output instead. Schemas are documented for each parser.
As a Python library, jc.parse('dig', cmd_output) returns a dictionary or list of dictionaries. Streaming parsers can return a lazy iterable of dictionaries. jc is also available as an Ansible filter plugin in the community.general collection. The README lists use cases in Bash scripting, Ansible, Saltstack, Nornir, and FortiSOAR. Typical users are sysadmins, DevOps engineers, and developers who write automation scripts.
Installation
# via Homebrew
brew install jc
# via apt
apt-get install jc
# via pip
pip3 install jc
Alternatives & related tools
visidata
Terminal interface for exploring and arranging tabular data with support for CSV, JSON, SQLite, Excel, and many other formats.
mycli
MySQL command line client with auto-completion, syntax highlighting, and smart context-aware SQL suggestions
pgcli
Interactive PostgreSQL client with auto-completion, syntax highlighting, and smart context-sensitive suggestions.
litecli
Command-line client for SQLite databases with auto-completion and syntax highlighting.
dolphie
Real-time terminal interface for monitoring MySQL/MariaDB and ProxySQL database performance and analytics
add a badge to your README
Maintain jc? Show that it's featured on trmn. The badge links back to this page.
[](https://www.trmn.sh/tools/jc?utm_source=badge)<a href="https://www.trmn.sh/tools/jc?utm_source=badge"><img src="https://www.trmn.sh/badge/jc.svg" alt="Featured on trmn" height="20"></a>