What Is JSON? A Complete Guide
JSON (JavaScript Object Notation) is the most widely used data interchange format on the web. Originally derived from JavaScript, JSON has become language-independent and is supported by virtually every modern programming language including Python, Java, C#, Go, Ruby, PHP, and many more.
JSON was first specified by Douglas Crockford in the early 2000s and later standardized as ECMA-404 and RFC 8259. Its simplicity and readability made it the de facto standard for APIs, configuration files, and data storage, largely replacing XML in modern applications.
JSON Data Types
JSON supports six data types:
- String — A sequence of Unicode characters enclosed in double quotes. Example:
"hello world" - Number — An integer or floating-point number. Example:
42,3.14,-1.5e10 - Boolean — Either
trueorfalse - Null — Represents an empty or missing value:
null - Object — An unordered collection of key-value pairs enclosed in curly braces
{} - Array — An ordered list of values enclosed in square brackets
[]
JSON Syntax Rules
Understanding JSON syntax rules is essential for writing valid JSON and debugging errors:
- Keys must be double-quoted strings. Single quotes and unquoted keys are not valid JSON.
{name: "John"}is invalid;{"name": "John"}is correct. - Strings must use double quotes. Single-quoted strings like
'hello'are not valid. Use"hello"instead. - No trailing commas. The last item in an object or array must not have a trailing comma.
{"a": 1, "b": 2,}is invalid. - No comments. JSON does not support comments. Use JSONC or JSON5 if you need comments.
- Special characters must be escaped. Characters like
\n,\,\", and\\must be escaped with a backslash.
Why Format JSON?
Raw JSON from APIs and log files is typically minified — all on a single line with no whitespace. While this is efficient for machines, it is nearly impossible for humans to read. JSON formatting (also called pretty-printing or beautifying) adds:
- Indentation — Usually 2 or 4 spaces per nesting level, making the hierarchy visible at a glance
- Line breaks — Each key-value pair and array element on its own line
- Alignment — Consistent structure that makes it easy to spot missing brackets or mismatched types
Formatted JSON is essential for debugging API responses, editing configuration files, reviewing data exports, writing documentation, and collaborative code reviews.
Common JSON Errors and How to Fix Them
When this tool shows "Invalid JSON," here are the most common causes and fixes:
1. Unexpected token error
Usually caused by single quotes, trailing commas, or unquoted keys. Replace single quotes with double quotes and remove any trailing commas.
2. Unterminated string
A string value is missing its closing double quote. Check for unescaped double quotes within string values — use \" to escape them.
3. Expected property name
An object has a missing or invalid key. Ensure every value in an object has a double-quoted key before the colon.
4. Unexpected end of input
The JSON is truncated or has mismatched brackets/braces. Count your opening and closing brackets to ensure they match.
JSON Formatting Best Practices
- Use 2-space indentation for web APIs — Keeps payloads compact while maintaining readability. Most JavaScript/TypeScript projects use 2 spaces.
- Use 4-space indentation for configuration files — More readable for deeply nested structures common in config files.
- Use minified JSON in production — Remove all whitespace for API responses and data transfer to reduce bandwidth and improve performance.
- Validate before deploying — Always validate JSON configuration files before deploying. A single syntax error can bring down an entire application.
- Keep nesting shallow — Deeply nested JSON (5+ levels) becomes hard to maintain. Consider flattening structures or splitting into multiple files.
- Use consistent key naming — Choose camelCase or snake_case and stick with it throughout your project.
JSON vs Other Data Formats
| Feature | JSON | XML | YAML | TOML |
|---|---|---|---|---|
| Readability | Good | Fair | Excellent | Excellent |
| Verbosity | Low | High | Very Low | Low |
| Comments | No | Yes | Yes | Yes |
| Data Types | 6 types | Text only | Rich | Rich |
| Parsing Speed | Fast | Slow | Medium | Fast |
| Primary Use | APIs | Documents | Config | Config |
How JSON Formatting Works Under the Hood
This tool uses the built-in JSON.parse() and JSON.stringify() functions available in every modern browser. Here is what happens when you click "Format":
- Your input string is parsed by
JSON.parse(input), which validates the syntax and creates a JavaScript object in memory. - If parsing fails, the exact error message (including the position of the error) is displayed.
- If parsing succeeds,
JSON.stringify(parsed, null, indent)converts the object back to a string with your chosen indentation. - For minification,
JSON.stringify(parsed)is called without the indent parameter, producing compact output with no whitespace.
Because everything runs in your browser, there is zero network latency and your data never leaves your device.
How to Format JSON Online — Step by Step
- 1. Paste your raw JSON string into the Input JSON panel on the left.
- 2. Select your preferred indentation — 2 spaces (compact) or 4 spaces (wide).
- 3. Click Format JSON to pretty-print with proper indentation and line breaks.
- 4. Click Minify to strip all whitespace for compact production output.
- 5. The Valid / Invalid badge provides real-time syntax validation as you type.
- 6. Click Copy to copy the formatted output to your clipboard instantly.
Frequently Asked Questions
How do I format JSON online?
Paste your JSON into the input field, select your preferred indentation (2 or 4 spaces), and click Format. The tool will pretty-print your JSON with proper indentation and line breaks, making it easy to read and debug.
Is this JSON formatter free to use?
Yes, this JSON formatting tool is completely free with no limits on usage, file size, or features. No signup or account is required. Use it as many times as you need.
What is the difference between JSON format and JSON minify?
JSON formatting (also called pretty-printing or beautifying) adds indentation and line breaks to make JSON human-readable. JSON minification does the opposite — it removes all unnecessary whitespace to produce the smallest possible output for production use, reducing bandwidth and improving load times.
Is my JSON data safe when using this tool?
Absolutely. All JSON formatting and validation happens locally in your browser using JavaScript. Your data is never sent to any server, stored, or logged. This makes it safe for formatting sensitive or proprietary JSON data.
What is valid JSON format?
Valid JSON must follow strict syntax rules: data is enclosed in curly braces {} for objects or square brackets [] for arrays, all keys must be double-quoted strings, values can be strings (double-quoted), numbers, booleans (true/false), null, objects, or arrays. Trailing commas and comments are not allowed.
Can I format large JSON files?
Yes. Since the tool runs entirely in your browser using native JSON.parse() and JSON.stringify(), it can handle large JSON files limited only by your browser's available memory. Most modern browsers can process JSON files up to 50MB without issues.
What causes "Unexpected token" errors in JSON?
The most common causes are: single quotes instead of double quotes around keys or string values, trailing commas after the last item in an object or array, unquoted keys, comments in the JSON (not supported), and unescaped special characters within strings.
How do I fix invalid JSON?
Paste your JSON into this tool and read the error message carefully — it tells you the exact position of the problem. Common fixes include: replacing single quotes with double quotes, removing trailing commas, adding missing commas between items, and ensuring all brackets and braces are properly matched.
What is the difference between JSON and JSONL?
JSON stores a single value (typically an object or array) in one file. JSONL (JSON Lines) stores one complete JSON value per line, separated by newlines. JSONL is ideal for streaming data, log files, and processing large datasets line by line without loading everything into memory.
Can I convert JSON to other formats?
Yes! FastDevKit offers several conversion tools. Use our JSON to CSV Converter to create spreadsheets, YAML-JSON Converter for configuration files, or JSON to TypeScript to generate type definitions. Check the related tools section below.