Guide
Formatting, validating and repairing JSON
JSON is everywhere: API responses, configuration files, log lines, exported data. It often arrives as one long, unreadable line, and a single stray comma makes the whole document invalid. This formatter makes JSON readable, tells you exactly where it’s broken, fixes the most common mistakes automatically, and lets you explore large documents as a tree.
Formatting and validating
- Paste JSON into the input, or open a .json file.
- Choose indentation: 2 spaces, 4 spaces, tabs, or Minify for the smallest possible output.
- Read the result. Valid JSON shows a summary: size in and out, the number of keys and array items, and the nesting depth.
- Copy the output or download it as formatted.json.
Formatting and validating happen together; there’s no separate validate button to forget.
Reading the error message
If the JSON is invalid, you’ll see the line and column of the first error and a short message. The reported position is where the parser gave up, which is often just after the real mistake. A missing comma at the end of line 12 is usually reported at the start of line 13.
The errors you’ll see most
| Error | Example | Fix |
|---|---|---|
| Trailing comma | {"a": 1,} |
Remove the last comma |
| Single quotes | {'a': 1} |
Use double quotes: {"a": 1} |
| Unquoted keys | {a: 1} |
Quote the key: {"a": 1} |
| Comments | // note |
JSON has no comments; remove them |
| Invalid values | undefined, NaN |
Use null or a number |
| Missing comma | {"a": 1 "b": 2} |
Add a comma between items |
| Unescaped quote or line break in a string | "say "hi"" |
Escape it: "say \"hi\"" |
Try to repair fixes the first four automatically: comments, trailing commas, single quotes and unquoted keys. Those are the differences between a JavaScript object pasted from code and strict JSON. Missing brackets and missing values can’t be guessed, so the formatter points to them instead.
Exploring large documents
Switch the output to Tree to fold and unfold objects and arrays. It’s the fastest way to find one field in a large API response: collapse everything, then open only the branch you need. The depth figure in the summary warns you when a document is deeply nested.
Sorting keys before comparing
JSON objects have no fixed key order, so two responses with identical data can look different. Turn on Sort keys to sort every object alphabetically, at every level, then compare the two outputs with the Diff Checker: only real differences remain.
Minify or pretty-print?
- Pretty-print (2 or 4 spaces) for reading, code review, documentation and configuration files.
- Minify for embedding in code, URLs, environment variables or anywhere size matters. The summary shows how much smaller it gets.
- Tabs if your project’s style guide uses them.
Privacy
Payloads often contain customer data, internal IDs or tokens. The formatter parses everything in your browser and sends nothing to a server, so it’s suitable for production data. Still remove secrets before sharing formatted output with others.
Who formats JSON
- Developers read API responses, configuration files and logs.
- Testers check payloads and compare responses between environments.
- Data analysts inspect exports from tools and APIs.
- Support engineers read error payloads customers send.
- Students learn the JSON format and find syntax errors.
A complete example: an API returns an error
- Copy the response body from your browser’s developer tools (Network tab) and paste it.
- If it’s minified, the formatted view shows the structure: error, code, message, details.
- Switch to Tree to fold everything except details.
- Copy the relevant part into the bug report, formatted, so others can read it.
Tips
- Sort keys before comparing two responses with the Diff Checker.
- Remove tokens and personal data before sharing payloads.
Related tools
- YAML to JSON for configuration written in YAML.
- CSV to JSON to turn spreadsheet data into JSON.
- JWT Decoder to read the JSON inside a token.
- Diff Checker to compare two JSON documents.
Checked against the current version of the JSON Formatter on .

