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
String value
"hello"

# A sequence of Unicode characters inside double quotes.

Number value
123.45

# JSON supports integers and decimals.

Boolean value
true

# Booleans are lowercase `true` and `false`.

Null value
null

# Represents an explicit empty value.

Boolean false vs null
{
  "enabled": false,
  "nickname": null
}

# These values are not interchangeable.

## Number gotchas
Avoid leading zeros
{
  "count": 7
}

# Leading zeros are invalid except for zero itself.

Scientific notation
{
  "distance": 1.23e6
}

# JSON supports exponent notation.

Do not use NaN or Infinity
{
  "value": 0
}

# They are not valid JSON numbers.

Inspect a value type with jq
jq 'type' <<< '123'

# Quickly verify the parsed type of a JSON value.

## String gotchas
Escape quotes inside strings
{
  "message": "She said \"hello\""
}

# Use backslash to include literal double quotes.

Use escape sequences for control characters
{
  "text": "line 1
line 2\tindented"
}

# Encode newlines and tabs inside strings.

Unicode escape sequence
{
  "currency": "\u20AC"
}

# Represent a character with a Unicode escape.

Recommended next

No recommendations yet.