JSON Format Examples
A complete reference of JSON formatting with real before-and-after examples. Covers every data type, nesting pattern, and common mistake. plus links to the live formatter tool.
JSON Data Types
All 6 Types in One Object
{
"name": "Alice",
"age": 30,
"score": 9.5,
"active": true,
"notes": null,
"tags": ["dev", "admin"]
}Types Explained
"name": → string (double quotes) "age": → integer (no quotes) "score": → number (decimal) "active": → boolean (true / false) "notes": → null (lowercase) "tags": → array (square brackets)
Nested Object Example
Compact (before)
{"user":{"name":"Bob","address":{"city":"NYC","zip":"10001"}}}Formatted (after)
{
"user": {
"name": "Bob",
"address": {
"city": "NYC",
"zip": "10001"
}
}
}Array of Objects Example
Compact (before)
[{"id":1,"name":"Alice"},{"id":2,"name":"Bob"}]Formatted (after)
[
{
"id": 1,
"name": "Alice"
},
{
"id": 2,
"name": "Bob"
}
]Common Mistakes
Missing comma
{ "a": 1 "b": 2 }{ "a": 1, "b": 2 }Trailing comma
["a", "b", "c",]
["a", "b", "c"]
Single-quoted keys
{ 'name': 'Alice' }{ "name": "Alice" }Unquoted key
{ name: "Alice" }{ "name": "Alice" }JSON Syntax Rules Summary
- Keys must be strings wrapped in double quotes
- String values must also use double quotes. never single quotes
- Numbers, booleans (
true/false), andnullare unquoted - Objects use curly braces
{}, arrays use square brackets[] - Items separated by commas. no trailing comma after the last item
- Whitespace (spaces, tabs, newlines) is ignored. it only affects readability
Frequently Asked Questions
What are the JSON data types?
JSON supports 6 types: string (double quotes), number, boolean (true/false), null, object (curly braces), and array (square brackets).
Can JSON keys use single quotes?
No. JSON keys must always be in double quotes. Single quotes are valid JavaScript but not valid JSON. This is a very common source of parse errors.
Is trailing comma allowed in JSON?
No. Trailing commas after the last property or element are not allowed in JSON. They work in JavaScript/TypeScript but will cause a JSON parse error.
Try It Live