ShellJune 29, 2025

JSON Formatting and Extraction

Aliases for formatting and extracting data from JSON using Python and jq, suitable for command-line usage.

Each entry keeps the writeup and source together, so the page reads like a clipped page from the archive rather than a detached utility screen.

The implementation

The detail page preserves the practical behavior of the original route: the writeup stays readable, the source remains copyable and syntax highlighted, and the item can still link back into the rest of the catalog.

json-helpers.sh
1# Using Python (almost always available)
2alias jsonpp='python -m json.tool'
3
4# Using jq (more powerful, needs installation)
5# brew install jq
6alias json='jq .'
7
8# Pretty print with colors
9alias jsonc='jq . -C'
10
11# Usage examples:
12# curl api.example.com/data | jsonpp
13# cat data.json | json
14# echo '{"name":"test"}' | jsonc
15
16# Extract specific fields with jq
17# cat data.json | jq '.users[].name'
18# curl api.example.com | jq '.data.items[] | {id, name}'

More from the lab

Related utilities

View full catalog