Learn/JSON Fundamentals

JSON Data Types

JSON defines exactly six data types. Every value in a JSON document is one of these types. Understanding them is the foundation for working with JSON in any programming language.

Beginner~15 min read

Overview: The Six JSON Types

Every value in a JSON document belongs to one of six types. There are four primitive types (string, number, boolean, null) and two structural types (object, array).

JSON Type Hierarchy

All Six Types — In Depth

Click any type above to jump to its section, or scroll through all six below.

string

String

Definition

A string is a sequence of zero or more Unicode characters enclosed in double quotes. It is the most common type in JSON, used for text values, identifiers, dates, URLs, and more.

Technical Details

Strings must use double quotes ("). Single quotes and backticks are not valid. Special characters must be escaped with a backslash: \" for quote, \\ for backslash, \n for newline, \t for tab, and \uXXXX for Unicode code points.

Syntax

String Syntaxjson
"hello world"
"line 1\nline 2"
"path: C:\\Users\\file"
"emoji: \u2764"

Example

String values in a user profilejson
1{
2 "firstName": "Douglas",
3 "lastName": "Crockford",
4 "email": "[email protected]",
5 "bio": "Creator of JSON.\nAuthor of \"JavaScript: The Good Parts\".",
6 "website": "https://www.crockford.com"
7}

Real-World Use Cases

API responses

User names, emails, error messages

Configuration

File paths, connection strings, URLs

Dates as strings

ISO 8601 format: "2026-03-28T12:00:00Z"

Enum-like values

"status": "active" instead of numeric codes

Common Mistakes

Wrong
{ 'name': 'John' }
Correct
{ "name": "John" }

JSON requires double quotes. Single quotes are invalid.

Wrong
{ "path": "C:\Users" }
Correct
{ "path": "C:\\Users" }

Backslashes must be escaped in JSON strings.

Wrong
{ "bio": "Line 1 Line 2" }
Correct
{ "bio": "Line 1\nLine 2" }

Literal newlines are invalid. Use \n escape sequence.

Best Practices

  • Always use double quotes for strings.
  • Use ISO 8601 format for dates: "2026-03-28T12:00:00Z".
  • Escape special characters properly (\n, \t, \", \\).
  • Use meaningful string values instead of numeric codes for readability.
number

Number

Definition

A number represents a numeric value. JSON numbers can be integers, decimals, or scientific notation. There is no distinction between integer and float — it is a single type.

Technical Details

JSON numbers follow the IEEE 754 double-precision format. They can be positive or negative, have decimal points, and use exponent notation (e/E). Leading zeros are not allowed (except 0.x). NaN, Infinity, and -Infinity are not valid JSON numbers.

Syntax

Number Syntaxjson
42
-17
3.14159
2.998e8
-1.602e-19
0

Example

Numeric values in scientific and everyday usejson
1{
2 "httpStatusCode": 200,
3 "pi": 3.14159265358979,
4 "temperature": -40,
5 "speedOfLight": 2.998e8,
6 "planckConstant": 6.626e-34,
7 "balance": 0.00
8}

Real-World Use Cases

HTTP status codes

200, 404, 500 — always integers

Prices & currency

19.99 — beware floating-point precision

Coordinates

latitude: 40.7128, longitude: -74.0060

Timestamps

Unix timestamps: 1711612800

Common Mistakes

Wrong
{ "count": 007 }
Correct
{ "count": 7 }

Leading zeros are not allowed in JSON numbers.

Wrong
{ "value": NaN }
Correct
{ "value": null }

NaN is not a valid JSON value. Use null for missing/undefined values.

Wrong
{ "price": "$19.99" }
Correct
{ "price": 19.99 }

Numbers should not include currency symbols — those make it a string.

Wrong
{ "count": +5 }
Correct
{ "count": 5 }

JSON does not allow a leading plus sign on numbers.

Best Practices

  • Use integers for counts, IDs, and status codes.
  • Be cautious with floating-point precision for currency (consider using cents as integers).
  • Use scientific notation for very large or very small values.
  • Never quote numbers unless they are identifiers (like phone numbers or ZIP codes).
boolean

Boolean

Definition

A boolean represents a logical true or false value. JSON uses lowercase "true" and "false" — not quoted, not capitalized.

Technical Details

Boolean is the simplest JSON type with only two possible values: true and false. They must be lowercase and unquoted. "true" (a string) and true (a boolean) are different types. There is no truthy/falsy concept in JSON.

Syntax

Boolean Syntaxjson
true
false

Example

Boolean flags in a user settings objectjson
1{
2 "isActive": true,
3 "isDeleted": false,
4 "emailVerified": true,
5 "hasPremiumAccess": false,
6 "settings": {
7 "darkMode": true,
8 "notifications": false,
9 "autoSave": true
10 }
11}

Real-World Use Cases

Feature flags

"enableBetaFeatures": true

User preferences

"darkMode": true, "notifications": false

Status indicators

"isActive": true, "isVerified": false

API parameters

"verbose": true, "dryRun": false

Common Mistakes

Wrong
{ "active": True }
Correct
{ "active": true }

JSON booleans must be lowercase. True/FALSE/True are invalid.

Wrong
{ "active": "true" }
Correct
{ "active": true }

"true" is a string, not a boolean. Remove the quotes.

Wrong
{ "count": 1 } // as boolean
Correct
{ "active": true }

JSON has no truthy/falsy. Use actual boolean values, not 0/1.

Best Practices

  • Always use true/false (lowercase, no quotes) for boolean values.
  • Name boolean keys with "is", "has", "can", or "should" prefixes for clarity.
  • Never use 0/1, "yes"/"no", or "true"/"false" strings as boolean substitutes.
null

Null

Definition

Null represents an intentionally empty or absent value. It is written as lowercase null without quotes.

Technical Details

null is a special literal that signifies "no value." It is not the same as an empty string (""), the number zero (0), or the boolean false. In most languages, JSON null maps to nil, None, null, or Nothing depending on the language.

Syntax

Null Syntaxjson
null

Example

Using null for absent or unknown valuesjson
1{
2 "firstName": "Jane",
3 "middleName": null,
4 "lastName": "Doe",
5 "phoneNumber": null,
6 "deletedAt": null,
7 "metadata": {
8 "lastLogin": "2026-03-28T10:00:00Z",
9 "lastLogout": null
10 }
11}

Real-World Use Cases

Optional fields

"middleName": null when user has none

Cleared values

"deletedAt": null (not yet deleted)

API responses

Fields that exist in schema but have no data

Database NULLs

Mapping SQL NULL to JSON null

Common Mistakes

Wrong
{ "value": Null }
Correct
{ "value": null }

JSON null must be lowercase. Null, NULL, and NONE are invalid.

Wrong
{ "value": "null" }
Correct
{ "value": null }

"null" is a string containing the text "null". Remove the quotes.

Wrong
{ "value": undefined }
Correct
{ "value": null }

undefined does not exist in JSON. Use null instead.

Best Practices

  • Use null when a field exists in the schema but has no value.
  • Prefer omitting a key entirely over setting it to null, unless schema requires it.
  • Document whether null means "not provided" vs "intentionally cleared" in your API docs.
object

Object

Definition

An object is an unordered collection of key-value pairs enclosed in curly braces { }. Keys must be strings, and values can be any JSON type.

Technical Details

Objects are the primary structural type in JSON. They map to dictionaries (Python), hash maps (Java), plain objects (JavaScript), and structs (Go/Rust). Keys must be unique within an object (though the spec does not strictly forbid duplicates, parsers handle them inconsistently).

Syntax

Object Syntaxjson
{
"key1": "value1",
"key2": 42,
"key3": { "nested": true }
}

Example

Nested object representing a user profilejson
1{
2 "user": {
3 "id": 1001,
4 "name": "Alice Chen",
5 "email": "[email protected]",
6 "address": {
7 "street": "123 Main St",
8 "city": "San Francisco",
9 "state": "CA",
10 "zip": "94105"
11 },
12 "roles": ["admin", "editor"]
13 }
14}

Real-World Use Cases

API payloads

Request and response bodies are almost always objects

Configuration

tsconfig.json, package.json, .eslintrc

Database documents

MongoDB documents are JSON-like objects

State management

Redux stores, React state objects

Common Mistakes

Wrong
{ name: "John" }
Correct
{ "name": "John" }

Object keys must be quoted strings in JSON.

Wrong
{ "a": 1, "a": 2 }
Correct
{ "a": 1, "b": 2 }

Duplicate keys cause unpredictable behavior. Use unique keys.

Wrong
{ "name": "John", }
Correct
{ "name": "John" }

Trailing commas are not allowed in JSON.

Best Practices

  • Use descriptive, camelCase key names for consistency.
  • Keep nesting to 3-4 levels maximum for readability.
  • Never use duplicate keys within the same object.
  • Order keys consistently (alphabetical or by logical grouping).
array

Array

Definition

An array is an ordered list of values enclosed in square brackets [ ]. Values can be any JSON type, and items can be of mixed types.

Technical Details

Arrays maintain insertion order (the first item is always index 0). They can contain any number of items, including zero (an empty array []). While mixed types are valid JSON, most APIs and schemas expect homogeneous arrays for type safety.

Syntax

Array Syntaxjson
[1, 2, 3]
["a", "b", "c"]
[true, false, null]
[{"id": 1}, {"id": 2}]
[]

Example

Arrays of objects, strings, and numbersjson
1{
2 "playlist": {
3 "name": "Focus Mode",
4 "tracks": [
5 {
6 "title": "Weightless",
7 "artist": "Marconi Union",
8 "durationMs": 480000
9 },
10 {
11 "title": "Electra",
12 "artist": "Airstream",
13 "durationMs": 312000
14 }
15 ],
16 "tags": ["ambient", "focus", "instrumental"],
17 "ratings": [4.8, 4.9, 4.7, 5.0]
18 }
19}

Real-World Use Cases

API lists

Collections of users, products, posts

Tags & categories

["javascript", "react", "nextjs"]

Coordinates

[40.7128, -74.0060] (lat, lng pair)

Matrix / grid data

[[1,2,3], [4,5,6], [7,8,9]]

Common Mistakes

Wrong
[1, 2, 3,]
Correct
[1, 2, 3]

Trailing commas are not allowed in JSON arrays.

Wrong
[1, 2, , 4]
Correct
[1, 2, null, 4]

Missing values create holes. Use null for explicit empty slots.

Best Practices

  • Use homogeneous arrays (same type for all items) when possible.
  • Prefer arrays of objects over parallel arrays for related data.
  • Use empty arrays [] instead of null when a list has no items.
  • Keep array items consistent in structure (same keys in every object).

Type Comparison Table

TypeExampleQuoted?JavaScript typeofPython type
String"hello"Yes (double)stringstr
Number42, 3.14Nonumberint / float
Booleantrue, falseNobooleanbool
NullnullNoobjectNoneType
Object{ "k": "v" }Keys: Yesobjectdict
Array[1, 2, 3]Noobject (Array)list

JSON Types vs JavaScript Types

While JSON borrows syntax from JavaScript, there are important differences:

JSON vs JavaScript Types

Key Difference

JavaScript has undefined, Date, RegExp, and Function types that JSON does not support. When serializing JavaScript to JSON, these values are either omitted or converted (e.g., Date becomes a string).

Try It Yourself

Edit this JSON to experiment with all six data types. Try changing types, introducing errors, or building your own structure. Click Run & Validate to check your work.

Try It Yourself

All six JSON types in one document

Frequently Asked Questions

How many data types does JSON have?
JSON has exactly six data types: String, Number, Boolean (true/false), Null, Object, and Array. Unlike JavaScript, JSON does not have undefined, Date, RegExp, or Function types.
Does JSON support integers and floats separately?
No. JSON has a single "number" type that covers both integers and floating-point values. The distinction between int and float is made by the parsing language, not by JSON itself.
Can JSON values be undefined?
No. "undefined" is not a valid JSON value. Use "null" instead when a value is intentionally absent. If a key has no value, omit the key entirely.
Are single quotes valid in JSON strings?
No. JSON requires double quotes for all strings. Single quotes are a syntax error. This is one of the most common mistakes developers make when writing JSON by hand.
Can JSON arrays contain mixed types?
Yes. A JSON array can contain values of any type: strings, numbers, booleans, null, objects, and other arrays. For example: ["hello", 42, true, null, {"key": "value"}]
What is the difference between null and empty string in JSON?
null means "no value" or "value is intentionally absent." An empty string "" is a valid string value that happens to contain no characters. They serve different semantic purposes.
Can JSON object keys be numbers?
No. JSON object keys must always be strings enclosed in double quotes. Even if the key looks like a number, it must be quoted: {"123": "value"} is valid, {123: "value"} is not.