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).
All Six Types — In Depth
Click any type above to jump to its section, or scroll through all six below.
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
"hello world""line 1\nline 2""path: C:\\Users\\file""emoji: \u2764"Example
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
{ 'name': 'John' }{ "name": "John" }JSON requires double quotes. Single quotes are invalid.
{ "path": "C:\Users" }{ "path": "C:\\Users" }Backslashes must be escaped in JSON strings.
{ "bio": "Line 1
Line 2" }{ "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
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
42-173.141592.998e8-1.602e-190Example
1{2 "httpStatusCode": 200,3 "pi": 3.14159265358979,4 "temperature": -40,5 "speedOfLight": 2.998e8,6 "planckConstant": 6.626e-34,7 "balance": 0.008}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
{ "count": 007 }{ "count": 7 }Leading zeros are not allowed in JSON numbers.
{ "value": NaN }{ "value": null }NaN is not a valid JSON value. Use null for missing/undefined values.
{ "price": "$19.99" }{ "price": 19.99 }Numbers should not include currency symbols — those make it a string.
{ "count": +5 }{ "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
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
truefalseExample
1{2 "isActive": true,3 "isDeleted": false,4 "emailVerified": true,5 "hasPremiumAccess": false,6 "settings": {7 "darkMode": true,8 "notifications": false,9 "autoSave": true10 }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
{ "active": True }{ "active": true }JSON booleans must be lowercase. True/FALSE/True are invalid.
{ "active": "true" }{ "active": true }"true" is a string, not a boolean. Remove the quotes.
{ "count": 1 } // as boolean{ "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
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
nullExample
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": null10 }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
{ "value": Null }{ "value": null }JSON null must be lowercase. Null, NULL, and NONE are invalid.
{ "value": "null" }{ "value": null }"null" is a string containing the text "null". Remove the quotes.
{ "value": undefined }{ "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
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
{ "key1": "value1", "key2": 42, "key3": { "nested": true }}Example
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
{ name: "John" }{ "name": "John" }Object keys must be quoted strings in JSON.
{ "a": 1, "a": 2 }{ "a": 1, "b": 2 }Duplicate keys cause unpredictable behavior. Use unique keys.
{ "name": "John", }{ "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
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
[1, 2, 3]["a", "b", "c"][true, false, null][{"id": 1}, {"id": 2}][]Example
1{2 "playlist": {3 "name": "Focus Mode",4 "tracks": [5 {6 "title": "Weightless",7 "artist": "Marconi Union",8 "durationMs": 4800009 },10 {11 "title": "Electra",12 "artist": "Airstream",13 "durationMs": 31200014 }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
[1, 2, 3,][1, 2, 3]Trailing commas are not allowed in JSON arrays.
[1, 2, , 4][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
| Type | Example | Quoted? | JavaScript typeof | Python type |
|---|---|---|---|---|
| String | "hello" | Yes (double) | string | str |
| Number | 42, 3.14 | No | number | int / float |
| Boolean | true, false | No | boolean | bool |
| Null | null | No | object | NoneType |
| Object | { "k": "v" } | Keys: Yes | object | dict |
| Array | [1, 2, 3] | No | object (Array) | list |
JSON Types vs JavaScript Types
While JSON borrows syntax from JavaScript, there are important differences:
Key Difference
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