JSON Syntax Guide
Data types, rules, examples, and common gotchas
The Six Data Types
JSON has exactly six value types. No more, no less.
| Type | Example | Notes |
|---|---|---|
| String | "hello" | Always double quotes. No single quotes. |
| Number | 42, -7, 3.14, 1e10 | No NaN or Infinity. No leading zeros. |
| Boolean | true, false | Lowercase only. |
| null | null | Lowercase only. Represents absence of value. |
| Object | {"key": "value"} | Keys must be strings in double quotes. |
| Array | [1, "two", true] | Ordered list, mixed types allowed. |
Complete Example
{
"name": "Alice",
"age": 30,
"active": true,
"score": 98.6,
"address": null,
"tags": ["developer", "designer"],
"location": {
"city": "New York",
"zip": "10001"
}
}Strings
Strings must use double quotes. Certain characters must be escaped with a backslash:
| Escape | Character |
|---|---|
| \" | Double quote |
| \\ | Backslash |
| \/ | Forward slash (optional) |
| \n | Newline |
| \t | Tab |
| \r | Carriage return |
| \b | Backspace |
| \f | Form feed |
| \uXXXX | Unicode code point (e.g. \u0041 = A) |
Numbers
✓ Valid numbers
42 -7 3.14 0.5 1.5e10 1.5E-3
✗ Invalid numbers
077 // No leading zeros .5 // Must start with digit NaN // Not supported Infinity // Not supported "42" // That's a string
Objects
Objects are unordered key-value pairs. Keys must be strings in double quotes. Trailing commas are not allowed.
✓ Valid object
{"a": 1, "b": 2}✗ Single-quoted keys
{'a': 1} // Keys must use double quotes✗ Trailing comma
{"a": 1, "b": 2,} // No trailing commas✗ Unquoted key
{a: 1} // Keys must be quotedArrays
Ordered lists. Values can be any JSON type, including mixed types.
✓ Valid arrays
[1, 2, 3]
["a", "b", "c"]
[1, "two", true, null, {"x": 1}]✗ Trailing comma
[1, 2, 3,] // No trailing commas
Comments
Standard JSON does not support comments. This is one of the most common frustrations with the format.
✗ Comments are not valid JSON
{
// This is a comment — INVALID
"name": "Alice" /* Also invalid */
}For configuration files that benefit from comments, consider JSONC (JSON with Comments, used by VS Code) or JSON5, both of which are supersets of JSON that add comment support.
Common Gotchas
undefined is not valid JSON
JavaScript's undefined has no JSON representation. JSON.stringify({ x: undefined }) silently omits the key. Use null when you need to represent an absent value.
Duplicate keys
Duplicate keys in an object are technically allowed by the JSON spec but discouraged — behaviour when parsing is implementation-defined. Most parsers use the last value.
Number precision
JSON numbers can represent any number, but JavaScript (and many languages) parse them as IEEE 754 doubles. Integers larger than 2^53 - 1 lose precision. Use strings for large IDs.
// This loses precision in JavaScript!
{ "id": 9007199254740993 }
// Use a string instead
{ "id": "9007199254740993" }Validate Your JSON
Use the JSON Formatter on io9.me to validate, format, and analyze any JSON — with clear error messages showing exactly where the problem is.
Online JSON Formatter, Validator & Converter
io9.me JSON Tools is a free, browser-based JSON formatter and validator. Paste raw JSON or upload a .json file to instantly format, validate, minify, or convert your data. All processing happens locally in your browser — nothing is sent to a server.
Features
- Format and beautify JSON with 2-space or 4-space indentation
- Validate JSON syntax with detailed error messages and line numbers
- Minify JSON by stripping whitespace for smaller payloads
- Convert JSON to YAML with a single click
- Compare two JSON documents side-by-side with structural diff highlighting
- Collapse and expand nested objects and arrays
- Upload .json files via drag-and-drop or file picker
- Download formatted or minified output
- Undo history to revert changes
- Keyboard-friendly Monaco editor with syntax highlighting
How to use
- Paste your JSON into the editor, or click Upload to load a file.
- Click Format to beautify, Validate to check syntax, Minify to compress, or To YAML to convert.
- Use Compare mode to diff two JSON documents side-by-side.
- Copy or download the result.
Common use cases
Pretty-print API responses, validate configuration files, minify JSON before embedding in code, convert JSON to YAML for Kubernetes manifests or CI/CD pipelines, and compare JSON payloads to find differences.