Member-only story
Parse JSON easily like a PRO
15 must know JQ operations and an Easy way to parse JSON files.
JQ : A Lightweight command line JSON processor. Its so simple and powerful.
Install JQ (Centos)
Install JQ (Other Platforms)
Download the sample JSON from
https://github.com/gchandra10/jqtutorial
Note : This JSON file has no root element. '.' is used.
1. View JSON file in readable format
$ jq '.' sample_nows.json
2. Read the First JSON element / object
$ jq 'first(.[])' sample_nows.json
3. Read the Last JSON element
$ jq 'last(.[])' sample_nows.json
4. Read top 3 JSON elements
$ jq 'limit(3;.[])' sample_nows.json