How to use jq for JSON parsing?

0117

jq is a powerful tool for parsing and manipulating JSON data. Here are some basic examples of how to use jq for JSON parsing:

  1. Basic Output: To pretty-print a JSON file:

    jq . file.json
  2. Extracting a Specific Field: To get the value of a specific key:

    jq '.key' file.json
  3. Filtering Arrays: To filter elements in an array:

    jq '.array[] | select(.field == "value")' file.json
  4. Mapping and Transforming: To create a new array with specific fields:

    jq '.array | map({newKey: .oldKey})' file.json
  5. 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!

0 Comments

no data
Be the first to share your comment!