JSON resource

JSON syntax reference: values, strings, numbers and objects

A practical JSON syntax reference based on RFC 8259 and ECMA-404. Learn the value types, string escapes, number rules and common invalid forms.

JSON is a text format for serialized data. It is small enough to read by hand and strict enough for programs to parse the same document in many languages. This page follows the syntax in RFC 8259 and ECMA-404.

The six JSON value types

A JSON value is an object, array, string, number, true, false or null. A JSON text can contain any one of these values, although API responses commonly use an object or an array at the top level.

TypeExampleNotes
Object{"id": 42}Unordered name/value pairs inside curly braces.
Array[1, 2, 3]Ordered values inside square brackets.
String"hello"Unicode text enclosed by double quotes.
Number-12.5e2Decimal notation with an optional fraction and exponent.
BooleantrueLowercase true or false.
NullnullThe lowercase literal null.
JSON
{
  "name": "Ada Lovelace",
  "active": true,
  "roles": ["author", "mathematician"],
  "address": null
}

Objects and arrays

An object starts with { and ends with }. Each member has a double-quoted name, a colon and a value. Separate members with commas. An array starts with [ and ends with ]; separate its values with commas.

JSON
{
  "users": [
    {"id": 1, "name": "Asha"},
    {"id": 2, "name": "Noah"}
  ]
}

Names in an object SHOULD be unique. When a document repeats a name, parsers disagree about whether the first value, last value or every value wins. If you need predictable behavior, remove duplicates before shipping the document. Tool Kumar keeps duplicate keys visible and flags them while you inspect the file.

Strings and escapes

Strings use double quotes. A quote, backslash or control character must be escaped. The short escapes are \",\\, \/, \b, \f, \n, \r and \t. A Unicode escape uses exactly four hexadecimal digits, such as \u00e9 for é.

JSON
{
  "quote": "She said \"hello\".",
  "path": "C:\\work\\data.json",
  "lineBreak": "first line\nsecond line",
  "accent": "\u00e9"
}

JSON strings can contain Unicode characters directly. Escape a character when the receiving system requires it or when an escaped form makes the document easier to transport. Do not use single quotes around JSON strings.

Numbers

A JSON number may have a minus sign, an integer, an optional fraction and an optional exponent. The integer cannot have a leading zero unless it is exactly zero. JSON has no NaN, Infinity or hexadecimal number literal.

ValidInvalidWhy
0, -7+7A plus sign is not allowed at the start.
12.512.A fraction needs at least one digit after the dot.
6.02e236eAn exponent needs digits, with an optional sign.
0.25025Nonzero integers cannot start with a zero.

JSON itself does not set a precision limit. A programming language may round large numbers when it loads them into a native number type. Keep identifiers and exact decimal values as strings when the consumer cannot preserve their digits.

Common invalid forms

JavaScript object literals look similar to JSON, but they allow syntax that JSON does not. Comments, trailing commas, single quotes, unquoted names, undefined, NaN and functions belong to JavaScript, not standard JSON.

JSON
// invalid JSON: comments are not part of the format
{
  name: 'Ada',
  "roles": ["author",],
}

The Tool Kumar JSON viewer reports the first error with its line and column. It can also offer repairs for common JSON-like input while leaving the original text available for review. Read the formatting and validation guide for a step-by-step workflow.

Standards and sources

Use the standards when a parser, API contract or data exchange needs a precise definition. The examples on this page are original educational examples and do not contain user data.