JQ
jq is a lightweight and flexible command-line JSON processor. https://jqlang.github.io/jq/download/ VSCode Extension https://marketplace.visualstudio.com/items?itemName=davidnussio.vscode-jq-playground
Download the sample JSON from
https://github.com/gchandra10/jqtutorialNote: This JSON file has no root element. '.' is used.
1. View JSON file in readable format
$ jq '.' sample_nows.json2. Read the First JSON element / object
$ jq 'first(.[])' sample_nows.json3. Read the Last JSON element
$ jq 'last(.[])' sample_nows.json4. Read top 3 JSON elements
$ jq 'limit(3;.[])' sample_nows.json5. Read 2nd & 3rd element. Remember, Python has the same format. LEFT Side inclusive, RIGHT Side exclusive
$ jq '.[2:4]' sample_nows.json6. Extract individual values. | Pipeline the output
$ jq '.[] | [.balance,.age]' sample_nows.json7. Extract individual values and do some calculations
$ jq '.[] | [.age, 65 - .age]' sample_nows.json8. Return CSV from JSON
9. Return Tab Separated Values (TSV) from JSON
10. Return with custom pipeline delimiter ( | )
11. Convert the number to string and return | delimited result
12. Process Array return Name (returns as list / array)
or (returns line by line)
13. Parse multi level values
14. Query values based on condition, say .index > 2
15. Sorting Elements
Use Cases
Last updated