JSON Formatter and Validator
Format, validate, and minify your JSON data with error detection and syntax highlighting.
How to Use the JSON Formatter?
Paste your JSON data below and choose an action: Format (beautify), Validate, or Minify your JSON.
What Is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. Despite its name, JSON is language-independent and supported by virtually every programming language. It was derived from JavaScript object literal syntax by Douglas Crockford in the early 2000s and is now the dominant data format for web APIs, configuration files, and client-server communication. JSON replaced XML in most modern web applications because it is simpler to read, write, and parse.
JSON Syntax Rules
JSON has a strict syntax — even a single misplaced comma or missing quote will make it invalid:
- Objects are enclosed in curly braces
{ }and contain key-value pairs separated by commas - Arrays are enclosed in square brackets
[ ]and contain ordered values separated by commas - Keys must always be strings in double quotes — single quotes and unquoted keys are invalid
- Values can be: strings, numbers, booleans (
true/false),null, objects, or arrays - No trailing commas — a comma after the last item in an object or array is invalid JSON
- No comments — JSON does not support comments (use JSONC or JSON5 if you need them)
JSON Data Types
| Type | Example | Notes |
|---|---|---|
| String | "Hello World" | Must use double quotes. Supports escape sequences (\n, \t, \", \\) |
| Number | 42, 3.14, -17, 1.5e10 | No leading zeros. No hex/octal. Supports scientific notation |
| Boolean | true, false | Lowercase only — True, TRUE, False are invalid |
| Null | null | Represents absence of value. Lowercase only |
| Object | {"key": "value"} | Unordered collection of key-value pairs |
| Array | [1, "two", true] | Ordered list of values. Can contain mixed types |
JSON vs XML Comparison
| Feature | JSON | XML |
|---|---|---|
| Readability | More concise, easier to scan | Verbose with opening/closing tags |
| File Size | Smaller (less markup overhead) | Larger (tag names repeated) |
| Data Types | Native strings, numbers, booleans, null | Everything is text (needs schema for types) |
| Comments | Not supported | Supported (<!-- -->) |
| Parsing Speed | Faster (simpler structure) | Slower (DOM parsing) |
| Best For | APIs, config files, web apps | Document markup, SOAP, legacy systems |
Common JSON Errors and How to Fix Them
- Trailing comma:
{"a": 1, "b": 2,}— Remove the comma after the last element. JSON does not allow trailing commas. - Single quotes:
{'key': 'value'}— JSON requires double quotes for both keys and string values. - Unquoted keys:
{key: "value"}— Keys must be strings in double quotes:{"key": "value"}. - Missing commas:
{"a": 1 "b": 2}— Add a comma between items:{"a": 1, "b": 2}. - Undefined/NaN:
{"value": undefined}— Usenullinstead.undefinedandNaNare JavaScript concepts, not valid JSON.
Tool Features
- Format / Beautify: Add proper indentation (2 or 4 spaces) and line breaks to make minified JSON readable. Essential for debugging API responses.
- Validate: Check if your JSON is syntactically correct. The validator pinpoints the exact line and character where an error occurs.
- Minify: Remove all whitespace, indentation, and line breaks to produce the smallest possible JSON string. Reduces file size for API transmission and storage.
- Error Detection: Detailed error messages tell you exactly what is wrong — missing comma, unexpected token, unterminated string, etc.
Working with JSON in Different Languages
- JavaScript:
JSON.parse(string)to parse,JSON.stringify(obj, null, 2)to format with 2-space indentation - Python:
json.loads(string)to parse,json.dumps(obj, indent=2)to format - PHP:
json_decode($string)to parse,json_encode($obj, JSON_PRETTY_PRINT)to format - Java: Use Jackson (
ObjectMapper) or Gson —new Gson().toJson(obj) - Command line:
cat data.json | python -m json.toolfor quick formatting, or usejqfor advanced querying
Frequently Asked Questions — JSON Formatter
JSON (JavaScript Object Notation) is a lightweight data interchange format used by APIs, config files, and web applications. Formatting (pretty-printing) adds indentation and line breaks to make nested structures readable. Minified JSON removes all whitespace to reduce file size for production use. Well-formatted JSON is essential for debugging API responses and config files.
Most frequent JSON errors: (1) Trailing commas after the last item in an object or array — not allowed in JSON (unlike JavaScript). (2) Single quotes instead of double quotes for strings. (3) Unquoted keys. (4) Comments — JSON does not support comments. (5) Undefined values — JSON allows null but not undefined. (6) Control characters in strings without proper escaping.
JSON is a text format derived from JavaScript object syntax but with stricter rules: keys must be double-quoted strings, values can only be strings, numbers, objects, arrays, booleans (true/false), or null. JavaScript objects allow unquoted keys, single quotes, functions, undefined, and comments. JSON is language-independent — it's used across Python, Java, PHP, and virtually every programming language.
Minify JSON for production API responses and data files to reduce payload size and bandwidth. Minification removes all whitespace, shrinking JSON by 20–40% typically. Keep JSON formatted in development for readability. For configuration files that humans edit, always keep formatted. For data transmitted over networks or stored in databases, minified is more efficient.
Standard JSON does not support comments or trailing commas. JSONC (JSON with Comments) is a superset used in VS Code settings files and some configuration formats — but it's not valid JSON. If you need to validate JSONC, strip comments first. Some tools like JSON5 extend JSON further to allow comments, trailing commas, and unquoted keys, but these are non-standard formats.