Parsing JSON in the Terminal (jq)
Concept & Overview
Modern cloud infrastructure, Kubernetes, Docker, and REST APIs all communicate in JSON. The jq command-line JSON processor is the industry standard tool for slicing, filtering, and mapping structured JSON data in terminal pipelines.
- Pretty-print and syntax validate JSON: cat api.json | jq '.' (or jq '.' api.json).
- Extract specific keys: jq '.version' api.json.
- Access array items and nested object fields: jq '.users[0].name' api.json.
- Output unquoted raw strings (ideal for shell variables): jq -r '.users[0].name' api.json.
api.json using cat api.json | jq '.'. Next, extract the nested name of the first user in raw format using jq -r '.users[0].name' api.json.Command Syntax Reference
| Command / Syntax | Description |
|---|---|
cat api.json | jq '.' | Pretty-print JSON data |
jq -r '.users[0].name' api.json | Extract raw nested string value from JSON |
Verification Objectives
These conditions will be automatically verified when you run commands inside the interactive terminal simulator:
- ○Pretty-print api.json with jq '.'
- ○Extract first user name with jq -r '.users[0].name'
Ready to complete Quest 111?
Test your skills live in the browser terminal with an emulated Linux filesystem, real-time command evaluation, and instant step-by-step hints.