JSON Cheatsheet

JSON syntax on one page. Reference when writing config files and API data.

Config Formats·28 commands·Last updated 2026-07-21
Back to Config Formats

Data Types 6

"string"
String (must use double quotes)
123 / -456 / 3.14
Number (integer or float)
true / false
Boolean
null
Null value
{"key": "value"}
Object (key-value pairs)
[1, 2, 3]
Array (ordered list)

Object 5

{"name": "tom"}
Simple object
{"name": "tom", "age": 20}
Multi-field object
{"user": {"name": "tom"}}
Nested object
{"users": [{"name": "tom"}]}
Object containing array
{"key with space": "value"}
Key can contain spaces (must be quoted)

Array 5

[1, 2, 3]
Number array
["a", "b", "c"]
String array
[{"id": 1}, {"id": 2}]
Object array
[[1, 2], [3, 4]]
2D array
[1, "text", true, null]
Mixed type array

Nested 3

{"user": {"name": "tom", "age": 20}}
Object nested in object
{"users": [{"name": "tom"}, {"name": "jerry"}]}
Object nested in array
[{"id": 1, "tags": ["a", "b"]}]
Array of objects with arrays

Common Patterns 4

{"code": 200, "message": "success"}
API response format
{"error": {"code": 404, "message": "Not found"}}
Error response
{"data": {"items": [], "total": 100}}
Paginated data
{"id": 1, "created_at": "2026-07-19T10:30:00Z"}
With timestamp

Validation 5

JSON.parse(str)
JavaScript parse JSON string
JSON.stringify(obj)
JavaScript object to JSON string
JSON.stringify(obj, null, 2)
Pretty-print (2-space indent)
jsonlint file.json
CLI JSON syntax validation
jq . file.json
CLI JSON pretty-print and query

💡 Tips

  • JSON keys must use double quotes — single quotes or unquoted keys are invalid.
  • JSON does not support comments. Use JSONC (JSON with Comments) if comments are needed.
  • Use ISO 8601 format for date/time (e.g., "2026-07-19T10:30:00Z").