JSON Cheat Sheet

Search quick JSON syntax reminders for objects, arrays, strings, escapes, booleans, nulls, parsing, and formatting.

Object

{
  "name": "Workshelve",
  "active": true
}

JSON objects use curly braces with quoted string keys.

Array

[
  "json",
  "yaml",
  "xml"
]

JSON arrays use square brackets and comma-separated values.

Nested data

{
  "tool": {
    "id": "json-parser",
    "tags": ["format", "data"]
  }
}

Objects and arrays can be nested freely as long as syntax stays valid.

String

{
  "title": "Hello world"
}

Strings must use double quotes in JSON.

Number

{
  "count": 25,
  "ratio": 0.75
}

JSON numbers do not use quotes unless you want them treated as strings.

Boolean

{
  "enabled": true,
  "archived": false
}

Boolean values are lowercase true and false.

Null

{
  "owner": null
}

Use null for an intentionally empty value.

Escaped text

{
  "message": "Line 1\nLine 2\tTabbed"
}

Use backslash escapes inside JSON strings for control characters.

Pretty print

JSON.stringify(value, null, 2)

This produces readable indented JSON in JavaScript.

Parse

JSON.parse(text)

Parsing turns JSON text into a JavaScript value and throws on invalid syntax.

Top-level array

[{"id":1},{"id":2}]

A JSON document can be an array, not only an object.

No comments

{
  "note": "JSON does not allow comments"
}

Standard JSON does not support comments, trailing commas, or single-quoted strings.

Strict syntax rules

JSON is stricter than JavaScript object literals, so keys and strings must use double quotes and comments are not allowed.

Numbers and strings differ

42 is a number; "42" is a string. Quoting a value changes its type, even when the text contains only digits.

Separate values with commas

Place commas between array items and object properties, but leave the final item without a trailing comma.

Related Tools