Jq Cheatsheet

Jq JSON query language for parsing, filtering, and transforming JSON data

JSON Processing6 commandsintermediate

Overview

Jq is a lightweight command-line JSON processor for slicing and transforming data.

Why It Matters

Jq is the essential tool for querying and transforming JSON from the command line.

Essential Commands

jq . data.json

Pretty-print JSON document

jq ".users[] | .name" data.json

Extract nested field values

jq "select(.active == true)" users.json

Filter objects by condition

jq ".items | length" data.json

Count array elements

curl api | jq ".results[0]"

Pipe API output into jq query

jq -r ".[] | @csv" data.json

Convert JSON objects to CSV rows

Quick Start

Start with the filter and select json objects

Key Concepts

Filter and select JSON objects

Transform and map array elements

Use pipes to chain queries

Pro Tips

  • Combine multiple commands for powerful workflows
  • Use aliases to speed up your command entry
  • Create scripts to automate repetitive tasks

Common Pitfalls to Avoid

  • Forgetting to check the documentation for edge cases
  • Running commands without understanding their full impact
  • Not testing changes in a safe environment first

Related Resources

13 items