Use jq to query and manipulate JSON data
jq is a lightweight command-line tool to quickly process your JSON data. I mainly use it to search ( grep ) and select specific fields of a JSON file, but it...
jq is a lightweight command-line tool to quickly process your JSON data.
I mainly use it to search (grep) and select specific fields of a JSON file, but it can also be used to transform (sed) and process (awk) the data.
Of course, the output is also nicely formatted.
If this peaks your interest head over to the download page.
data.json{"persons": [{"id": 1,"name": "Bob"},{"id": 2,"name": "Alice"}],"lastModified": "2023-11-26"}
jq .lastModified data.json> "2023-11-26"
jq .persons[1]> {"id": 2,"name": "Alice"}
jq .persons.[].name data.json> "Bob"> "Alice"
jq .persons[0].id, .lastModified data.json> 1> "2023-11-26"
While these examples are simple and are using a local data source, you can feed data to jq using the pipe (|) operator.
curl 'https://api.github.com/repos/jqlang/jq/commits?per_page=5' | jq '.'
Make sure to check out the tutorial and the playground to also learn how to fully take advantage of jq by transforming and filtering JSON data.
Feel free to update this developer bit on GitHub, thanks in advance!