tips
9 tips Json
One command, setting or habit at a time about Json: what it does, the line to copy and a caveat or two.
Text processing 9
-
Parses a string field that itself contains JSON, so you can filter into it.
echo '{"id":1,"payload":"{\"user\":\"ann\",\"tags\":[\"x\",\"y\"]}"}' | jq -c '.payload | fromjson | .tags' -
Catch a broken config before the program that reads it does.
jq empty config.json -
Find the exact route to a value without scrolling through nested output.
-
Add names from one export to records in another without writing a program.
jq -c --slurpfile u users.json ' -
Process a file that is too big for a normal jq run.
jq -cn --stream 'fromstream(1|truncate_stream(inputs))' big.json -
Convert dates once while parsing instead of all over your code.
const text = '{"createdAt":"2026-11-30T09:00:00Z","name":"x"}'; -
Prints every jq result as one compact line, ready for loops and line-based tools.
jq -c '.[]' hosts.json -
Removes chosen keys or array items from JSON, so you can share a config without secrets.
jq 'del(.password)' config.json -
Collects every JSON value from the input into one array, so you can count, sum or merge them.
jq -s 'length' events.jsonl
Nothing in this filter yet.