jq is a powerful tool for parsing and manipulating JSON data. Here are some basic examples of how to use jq for JSON parsing:
-
Basic Output: To pretty-print a JSON file:
jq . file.json -
Extracting a Specific Field: To get the value of a specific key:
jq '.key' file.json -
Filtering Arrays: To filter elements in an array:
jq '.array[] | select(.field == "value")' file.json -
Mapping and Transforming: To create a new array with specific fields:
jq '.array | map({newKey: .oldKey})' file.json -
Combining Filters: To extract nested fields:
jq '.parent.child' file.json
These examples should help you get started with jq. If you have a specific JSON structure or query in mind, feel free to share, and I can provide more tailored examples!
