iproute2 & systemd output in JSON format

TL;DR

Didn’t notice ip provided by iproute2 supports output in JSON format until I read about the motivation behind jc.

Example

1
2
3
ip -j a | jq
ip -j r | jq
ip -j -s link | jq

main()


Must have JSON CLI utils for more productivity:

  • jq - who doesn’t know? sed for JSON data
  • gron - makes JSON greppable. Super useful for people like me who cannot figure out the jq filters by simply looking at JSON code, get enlightened by gron and gron --ungron.
  • jc - ideal for COMMAND | jc PARSER [OPTIONS] use cases

In addition to iproute2, some systemd provided *ctl command supports JSON output format as well. Most commonly used ones

  • systemctl
  • journalctl

Examples

1
2
3
4
5
6
# systemctl status
systemctl status sshd.service -o json
systemctl status -l sshd.service -o json

# journalctl
journalctl --since yesterday --output json

Have fun processing JSON with turbocharged productivity ;-)

EOF