JSON Types and Values

Examples and edge cases for strings, numbers, booleans, null, arrays, and objects in JSON.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Primitive values

JSON has a small, fixed set of primitive value types.

String value

A sequence of Unicode characters inside double quotes.

jsonANYjsonstring
json
"hello"

Strings must use double quotes in standard JSON.

Number value

JSON supports integers and decimals.

jsonANYjsonnumber
json
123.45

JSON has a single number type; parsers may map it differently by language.

Boolean value

Booleans are lowercase `true` and `false`.

jsonANYjsonboolean
json
true

`True` and `False` are invalid in JSON.

Null value

Represents an explicit empty value.

jsonANYjsonnull
json
null

Useful for partial updates, missing values, and API responses.

Boolean false vs null

These values are not interchangeable.

jsonANYjsonbooleannull
json
{
  "enabled": false,
  "nickname": null
}

`false` means the feature is disabled. `null` means there is no value.

Number gotchas

Common JSON number formats that trip people up.

Avoid leading zeros

Leading zeros are invalid except for zero itself.

jsonANYjsonnumberssyntax
json
{
  "count": 7
}

`007` is invalid JSON.

Scientific notation

JSON supports exponent notation.

jsonANYjsonnumbersscientific-notation
json
{
  "distance": 1.23e6
}

Useful for large or very small numeric values.

Do not use NaN or Infinity

They are not valid JSON numbers.

jsonANYjsonnumbersinvalid
json
{
  "value": 0
}

Some JavaScript values do not serialize into standard JSON as raw literals.

Inspect a value type with jq

Quickly verify the parsed type of a JSON value.

bashANYjsonjqtypes
bash
jq 'type' <<< '123'

Helpful when checking how a parser sees a value after serialization.

String gotchas

Escapes, Unicode, and practical string examples.

Escape quotes inside strings

Use backslash to include literal double quotes.

jsonANYjsonstringescape
json
{
  "message": "She said \"hello\""
}

Unescaped double quotes end the string and break parsing.

Use escape sequences for control characters

Encode newlines and tabs inside strings.

jsonANYjsonstringnewlinetab
json
{
  "text": "line 1
line 2\tindented"
}

Use escaped characters rather than raw line breaks inside a JSON string.

Unicode escape sequence

Represent a character with a Unicode escape.

jsonANYjsonstringunicode
json
{
  "currency": "\u20AC"
}

`€` represents the euro symbol.

Recommended next

No recommendations yet.