JSON Formatter
Format, validate, and minify JSON.
JSON Syntax Basics
JSON (JavaScript Object Notation) follows strict syntax rules:
- Data is in name/value pairs:
"name": "value" - Objects are wrapped in curly braces:
{ } - Arrays are wrapped in square brackets:
[ ] - Strings must use double quotes, not single quotes
- No trailing commas allowed after the last item
- No comments are allowed in JSON
JSON Data Types
JSON supports six data types. Understanding them helps you structure data correctly and avoid validation errors.
Strings are text wrapped in double quotes. Special characters like newlines need escape sequences like \n. Unicode is fully supported.
Numbers can be integers or decimals, positive or negative. Scientific notation works too. But no leading zeros, no NaN, no Infinity.
Booleans are lowercase true or false. No quotes around them. Using "true" makes it a string, not a boolean.
Null represents an empty or missing value. Lowercase null, no quotes. Different from an empty string or zero.
Arrays are ordered lists in square brackets. They can contain any mix of data types, including other arrays and objects.
Objects are key-value pairs in curly braces. Keys must be strings. Values can be any type. Objects can nest indefinitely.
Common JSON Errors
Watch out for these frequent mistakes:
- Trailing commas like {"a": 1,} need the final comma removed
- Single quotes like 'text' should be double quotes
- Unquoted keys like {name: "value"} must be wrapped in quotes
- Newlines and tabs inside strings need to be escaped
- Leading zeros on numbers like 007 are not valid
When to Minify vs Format
Minify when you need to reduce file size for API responses, store JSON in databases or localStorage, or transmit data over networks efficiently.
Format (beautify) when you need to debug or review data structure, edit configuration files, or document API examples.
JSON Validation
This formatter validates your JSON as it processes it. If you see an error, the message tells you what went wrong and roughly where. Common issues include missing quotes around keys, trailing commas after the last item, and using single quotes instead of double quotes. JSON is strict by design, so even small syntax errors will cause the entire document to fail parsing.
Where JSON Gets Used
JSON has become the standard format for data exchange on the web. You will encounter it almost everywhere.
REST APIs use JSON for request and response bodies. When you fetch data from any modern API, you are almost certainly receiving JSON.
Configuration files like package.json, tsconfig.json, and .eslintrc use JSON to store settings. These files control how tools and applications behave.
Databases like MongoDB store data in JSON-like documents. Browser localStorage and sessionStorage hold JSON strings. Redis can store JSON with modules.
Microservices communicate using JSON over HTTP. Event-driven systems pass JSON payloads. Even log aggregators often expect JSON-formatted log entries.