Try the
jc
web demo!
I’m happy to announce that jc
version 1.7.1 has been released and is available on github and pypi. In addition to the new and updated parsers and features outlined below, some back-end code cleanup to improve performance along with minor bug fixes were completed.
To upgrade, run:
$ pip3 install --upgrade jc
New Parsers
jc
now includes 37 parsers! New parsers (tested on linux and OSX) include id
, crontab-u
, INI
, XML
, and YAML
:
id
parser
Linux and OSX support for the id
command:
$ id | jc --id -p { "uid": { "id": 1000, "name": "joeuser" }, "gid": { "id": 1000, "name": "joeuser" }, "groups": [ { "id": 1000, "name": "joeuser" }, { "id": 10, "name": "wheel" } ], "context": { "user": "unconfined_u", "role": "unconfined_r", "type": "unconfined_t", "level": "s0-s0:c0.c1023" } }
crontab
files with user defined
Some crontab
files contain the user field. In this case, use the new crontab-u
parser:
$ cat /etc/crontab | jc --crontab-u -p { "variables": [ { "name": "MAILTO", "value": "root" }, { "name": "PATH", "value": "/sbin:/bin:/usr/sbin:/usr/bin" }, { "name": "SHELL", "value": "/bin/bash" } ], "schedule": [ { "minute": [ "5" ], "hour": [ "10-11", "22" ], "day_of_month": [ "*" ], "month": [ "*" ], "day_of_week": [ "*" ], "user": "root", "command": "/var/www/devdaily.com/bin/mk-new-links.php" }, { "minute": [ "30" ], "hour": [ "4/2" ], "day_of_month": [ "*" ], "month": [ "*" ], "day_of_week": [ "*" ], "user": "root", "command": "/var/www/devdaily.com/bin/create-all-backups.sh" }, { "occurrence": "yearly", "user": "root", "command": "/home/maverick/bin/annual-maintenance" }, { "occurrence": "reboot", "user": "root", "command": "/home/cleanup" }, { "occurrence": "monthly", "user": "root", "command": "/home/maverick/bin/tape-backup" } ] }
INI
file parser
Convert generic INI
files to JSON:
$ cat example.ini [DEFAULT] ServerAliveInterval = 45 Compression = yes CompressionLevel = 9 ForwardX11 = yes [bitbucket.org] User = hg [topsecret.server.com] Port = 50022 ForwardX11 = no $ cat example.ini | jc --ini -p { "bitbucket.org": { "serveraliveinterval": "45", "compression": "yes", "compressionlevel": "9", "forwardx11": "yes", "user": "hg" }, "topsecret.server.com": { "serveraliveinterval": "45", "compression": "yes", "compressionlevel": "9", "forwardx11": "no", "port": "50022" } }
XML
file parser
Convert generic XML
files to JSON:
$ cat cd_catalog.xml <?xml version="1.0" encoding="UTF-8"?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> ... $ cat cd_catalog.xml | jc --xml -p { "CATALOG": { "CD": [ { "TITLE": "Empire Burlesque", "ARTIST": "Bob Dylan", "COUNTRY": "USA", "COMPANY": "Columbia", "PRICE": "10.90", "YEAR": "1985" }, { "TITLE": "Hide your heart", "ARTIST": "Bonnie Tyler", "COUNTRY": "UK", "COMPANY": "CBS Records", "PRICE": "9.90", "YEAR": "1988" }, ... }
YAML
file parser
Convert YAML
files to JSON – even files that contain multiple YAML
documents:
$ cat istio-mtls-permissive.yaml apiVersion: "authentication.istio.io/v1alpha1" kind: "Policy" metadata: name: "default" namespace: "default" spec: peers: - mtls: {} --- apiVersion: "networking.istio.io/v1alpha3" kind: "DestinationRule" metadata: name: "default" namespace: "default" spec: host: "*.default.svc.cluster.local" trafficPolicy: tls: mode: ISTIO_MUTUAL $ cat istio-mtls-permissive.yaml | jc --yaml -p [ { "apiVersion": "authentication.istio.io/v1alpha1", "kind": "Policy", "metadata": { "name": "default", "namespace": "default" }, "spec": { "peers": [ { "mtls": {} } ] } }, { "apiVersion": "networking.istio.io/v1alpha3", "kind": "DestinationRule", "metadata": { "name": "default", "namespace": "default" }, "spec": { "host": "*.default.svc.cluster.local", "trafficPolicy": { "tls": { "mode": "ISTIO_MUTUAL" } } } } ]
Updated Parsers
history
parser now outputsline
fields as integerscrontab
parser bug fix for an issue that sometimes lost a row of data- Updated the compatibility information for
du
andhistory
parsers
__version__
Attribute Added
Python programmers can now call the __version__
attribute on all parsers when running them as modules.
>>> import jc.parsers.arp >>> print(jc.parsers.arp.__version__) 1.1
Added Exit Codes
jc
will now provide an exit code (1) if it did not successfully exit.
Schema Changes
The history
parser now outputs line
fields as integers
$ history | jc --history -p [ { "line": 118, "command": "sleep 100" }, ... ]
Full Parser List
arp
crontab
crontab-u
df
dig
du
env
free
fstab
history
hosts
id
ifconfig
INI
iptables
jobs
ls
lsblk
lsmod
lsof
mount
netstat
pip list
pip show
ps
route
ss
stat
systemctl
systemctl list-jobs
systemctl list-sockets
systemctl list-unit-files
uname -a
uptime
w
XML
YAML
For more information on the motivations for creating
jc
, see my blog post.
Happy parsing!