
JC
JSON Convert
jc JSONifies the output of many CLI tools, file-types, and common strings
for easier parsing in scripts. See the Parsers section for
supported commands, file-types, and strings.
dig example.com | jc --dig
[{"id":38052,"opcode":"QUERY","status":"NOERROR","flags":["qr","rd","ra"],
"query_num":1,"answer_num":1,"authority_num":0,"additional_num":1,
"opt_pseudosection":{"edns":{"version":0,"flags":[],"udp":4096}},"question":
{"name":"example.com.","class":"IN","type":"A"},"answer":[{"name":
"example.com.","class":"IN","type":"A","ttl":39049,"data":"93.184.216.34"}],
"query_time":49,"server":"2600:1700:bab0:d40::1#53(2600:1700:bab0:d40::1)",
"when":"Fri Apr 16 16:09:00 PDT 2021","rcvd":56,"when_epoch":1618614540,
"when_epoch_utc":null}]
Pipe the output to tools like jq or jello,
or use the "magic" syntax by putting jc in front of the command:
$ dig example.com | jc --dig | jq -r '.[].answer[].data'
93.184.216.34
$ jc dig example.com | jq -r '.[].answer[].data'
93.184.216.34
jc can also be used as a Python library. It returns a dictionary, a list of
dictionaries, or a
lazy iterable of dictionaries
instead of JSON:
>>> import subprocess
>>> import jc
>>>
>>> cmd_output = subprocess.check_output(['dig', 'example.com'], text=True)
>>> data = jc.parse('dig', cmd_output)
>>>
>>> data[0]['answer']
[{'name': 'example.com.', 'class': 'IN', 'type': 'A', 'ttl': 29658, 'data':
'93.184.216.34'}]
For library documentation, use help('jc') or see the
online documentation.
By default, output follows a documented schema for each parser: known numbers,
booleans, and null values are converted, and some parsers add fields such as
epoch timestamps. Use the -r option (or raw=True in parse()) for raw
output that stays closer to the original text. Each parser's schema is linked
from the Parsers table.
Release notes are in the Releases section on Github.
Try jc in the web demo, or run it as a
service with the REST API.
Further Reading
Installation
Install jc with pip, an OS package manager, or a precompiled binary that
runs from anywhere on your filesystem.
Pip (macOS, linux, unix, Windows)
pip3 install jc
OS Package Repositories
| OS |
Command |
| Debian/Ubuntu linux |
apt-get install jc |
| Fedora linux |
dnf install jc |
| openSUSE linux |
zypper install jc |
| Arch linux |
pacman -S jc |
| NixOS linux |
nix-env -iA nixpkgs.jc or nix-env -iA nixos.jc |
| Guix System linux |
guix install jc |
| Gentoo Linux |
emerge dev-python/jc |
| Photon linux |
tdnf install jc |
| macOS |
brew install jc |
| FreeBSD |
portsnap fetch update && cd /usr/ports/textproc/py-jc && make install clean |
| Ansible filter plugin |
ansible-galaxy collection install community.general |
| FortiSOAR connector |
Install from FortiSOAR Connector Marketplace |
For more OS Packages, see https://repology.org/project/jc/versions.
Binaries
For precompiled binaries, see Releases
on Github.
Usage
jc reads command output, a file, or a string from STDIN and writes JSON to
STDOUT:
COMMAND | jc [SLICE] [OPTIONS] PARSER
cat FILE | jc [SLICE] [OPTIONS] PARSER
echo STRING | jc [SLICE] [OPTIONS] PARSER
With the "magic" syntax, put jc and its options in front of the command or
/proc file path instead (command aliases and shell builtins are not
supported):
jc [SLICE] [OPTIONS] COMMAND
jc [SLICE] [OPTIONS] /proc/<path-to-procfile>
Output is compact JSON by default. Use -p to pretty-print it.
Parsers