Tested with: jq 1.7, Python 3
JSON (JavaScript Object Notation) is a text format for structured data. It is used in REST APIs, configuration files (AWS IAM policies, package.json, Claude Code settings) and log pipelines.
Object: { "key": value }. Keys are always strings in double quotes.
Array: [ value, value ].
Values: string "text", number 42 / 3.14, true, false, null, object or array.
Strings use double quotes only. Escapes: \", \\, \n, \t, \uXXXX.
No trailing commas, no comments.
A file contains one root value, usually an object or an array.
Sample.json
{
"name": "Billy Bob",
"role": "Developer",
"age": 32,
"active": true,
"manager": null,
"skills": ["python", "bash", "terraform"],
"servers": [
{ "host": "web01", "ip": "10.0.0.11", "env": "prod" },
{ "host": "web02", "ip": "10.0.0.12", "env": "stage" }
]
}
sudo apt install jq
jq . Sample.json # Pretty-print (fails on invalid JSON)
jq empty Sample.json # Validate only: no output and exit code 0 if valid
python3 -m json.tool Sample.json # Alternative without jq
An invalid file shows the exact position of the error:
echo '{"a": 1,}' | jq empty
# jq: parse error: Expected another key-value pair at line 1, column 9
jq -r '.name' Sample.json # Billy Bob
jq '.skills[0]' Sample.json # "python"
jq -r '.skills[]' Sample.json # Each item on its own line
jq '.servers | length' Sample.json # 2
jq -r '.servers[] | select(.env == "prod") | .ip' Sample.json # 10.0.0.11
jq -r '.servers[] | "\(.host) \(.ip)"' Sample.json # web01 10.0.0.11 ...
jq '.active = false' Sample.json > new.json # Change a value
-r prints raw strings without quotes, which is useful in shell scripts.