Syntax
Rules
{ }Object (unordered key-value pairs)
[ ]Array (ordered list of values)
"key": valueKeys must be double-quoted strings
No trailing commaLast item must not have a comma
No commentsJSON does not allow comments
Minimal Example
{ "name": "Alice", "age": 30, "active": true }
Data Types
Six Value Types
"string"Double-quoted UTF-8 text
42 / 3.14Number (integer or floating point)
true / falseBoolean
nullNull (absence of value)
{ }Object
[ ]Array
String Escape Sequences
\"Double quote
\\Backslash
\n \tNewline, tab
\uXXXXUnicode escape (hex)
Objects
Object Syntax
{ "id": 1, "name": "Widget", "tags": ["new", "sale"] }
Rules
KeysMust be unique double-quoted strings
ValuesAny valid JSON type
OrderKey order is not guaranteed
NestingObjects can contain objects
Arrays
Array Syntax
[1, "two", true, null, {"key": "val"}]
Mixed Type Array
{ "matrix": [[1, 2], [3, 4]], "empty": [] }
Rules
OrderedElements maintain insertion order
Mixed typesArray items can be different types
IndexingZero-based (in most languages)
Nesting
Nested Structure
{ "user": { "name": "Alice", "address": { "city": "Boston" }, "scores": [95, 88, 72] } }
Access Patterns
obj.user.nameDot notation (JavaScript)
obj["user"]["name"]Bracket notation
obj.user.scores[0]Array index within nested object
Schema Validation
JSON Schema Example
{ "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer", "minimum": 0 } }, "required": ["name"] }
Schema Keywords
typestring, number, integer, boolean, object, array, null
requiredArray of required property names
propertiesDefines expected object properties
enumRestrict to a fixed set of values
minLength / maxLengthString length constraints
minimum / maximumNumber range constraints
jq Basics
Common Filters
.Identity — pass input through
.keyAccess object key
.key.nestedAccess nested key
.[0]First array element
.[]Iterate all array elements
select(.age > 20)Filter by condition
map(.name)Transform each element
lengthArray length or string length
keysObject keys as array
jq Examples
echo '{"a":1}' | jq '.a' # 1 echo '[1,2,3]' | jq 'map(. * 2)' # [2,4,6] cat data.json | jq '.users[].name' cat data.json | jq '.[] | select(.active)'
Common Patterns
API Response
{ "status": 200, "data": [{"id": 1, "name": "Alice"}], "meta": {"total": 42, "page": 1} }
Config File
{ "host": "localhost", "port": 8080, "debug": false, "features": ["auth", "logging"] }
Tips
ValidateUse jsonlint or python -m json.tool
Pretty printjq . file.json or python -m json.tool
JSONLOne JSON object per line (newline-delimited)
JSON5 / JSONCExtensions allowing comments and trailing commas