Code & JSON Tools · · 4 min read
How to Format and Validate JSON (and Fix the Most Common Errors)
Pretty-print, minify and validate JSON in seconds, understand what makes JSON invalid, and fix the errors you'll hit most — trailing commas, quotes and more.
To format JSON, paste it into a JSON formatter such as the Toolbench JSON Formatter and choose an indentation. It parses your JSON, tells you straight away whether it's valid, and returns a neatly indented version (or a minified one-liner) you can copy. If the JSON is broken, you get the parser's error message instead, so you know what to fix.
This guide covers when to pretty-print versus minify, the rules JSON must follow, and how to fix the errors that trip people up most.
What a JSON formatter does
JSON (JavaScript Object Notation) is the standard format APIs, config files and databases use to exchange data. Machines don't care about whitespace, so JSON often arrives as one long unreadable line. A formatter:
- Validates the text against JSON's grammar.
- Pretty-prints it with consistent indentation so nesting is obvious.
- Minifies it back to a single line when you need the smallest payload.
- Optionally sorts keys alphabetically so two objects are easy to compare.
How to format JSON with Toolbench
- Open the JSON Formatter.
- Paste your JSON into the input panel.
- Pick 2 spaces, 4 spaces or Minify.
- Turn on Sort keys if you want every object's keys in alphabetical order — this applies to nested objects too.
- Copy the output, or use Send to to open it in another tool.
When the input is valid, the status line shows a green tick with the number of keys, the nesting depth and the output size in bytes — a handy quick check that you pasted the whole payload.
Pretty-print or minify?
| Use pretty-printed JSON when… | Use minified JSON when… |
|---|---|
| You're reading or debugging an API response | You're sending data over the network |
| You're editing a config file by hand | You're storing JSON in a database column |
| You want readable diffs in version control | Every byte counts (embedded data, URLs) |
Formatting never changes your data — only whitespace. Sorting keys changes the order keys appear in, which JSON treats as insignificant, so the data is still equivalent.
The rules valid JSON must follow
JSON looks like JavaScript, but it's stricter. Valid JSON:
- Uses double quotes for every string and every key:
{"name": "Ana"}. - Allows only these values: strings, numbers,
true,false,null, objects and arrays. - Has no trailing commas after the last item in an object or array.
- Has no comments — neither
//nor/* */. - Doesn't allow
undefined,NaN,Infinityor functions. - Must be a single value at the top level (usually one object or one array).
Fixing the most common JSON errors
Trailing comma
{ "name": "Ana", "role": "Designer", }
Remove the comma after the last property. This is the single most common error, especially in hand-edited config files.
Single quotes
{ 'name': 'Ana' }
Replace single quotes with double quotes around both keys and string values.
Unquoted keys
{ name: "Ana" }
JavaScript allows this; JSON doesn't. Quote the key: "name".
Comments
JSON has no comment syntax. Delete comments, or, if you control the format, move notes into a real field such as "_comment": "...".
Missing bracket or brace
Usually caused by copying only part of a response. The error position points near the end of the input. Re-copy the full payload — the key count and depth on a successful parse are a good way to confirm you have all of it.
Smart quotes from documents
JSON copied from Word, Google Docs or a chat app often contains curly quotes (“ ”), which are not valid. Run the text through the Text Cleaner with smart-quote fixing on, then format again.
Related JSON tools
- JSON Validator — pinpoints the exact line and column of an error.
- JSON Viewer & Editor — explore big payloads as a collapsible tree and copy the path to any value.
- CSV to JSON and JSON to CSV — move data between spreadsheets and APIs.
- JSON Minify — strip whitespace in one step.
Frequently asked questions
Is my JSON sent to a server when I format it?
No. Parsing and formatting happen in your browser with its built-in JSON parser, so API keys, tokens or customer data in your payload stay on your device.
Why does my JSON work in JavaScript but fail validation?
JavaScript object literals are more permissive than JSON. Single quotes, unquoted keys, trailing commas and comments are all fine in JavaScript code but invalid in JSON.
Does formatting change the data?
No. Pretty-printing and minifying only change whitespace. Sorting keys reorders object keys, which doesn't change the meaning of the data.
What indentation should I use for JSON?
Two spaces is the most common convention and keeps deeply nested data readable without scrolling sideways. Four spaces is also common; pick one and use it consistently.
How do I see where the error is?
When the JSON is invalid, the formatter shows the parser's error message in place of the output. For an exact line and column, paste it into the JSON Validator.
More guides
- How to Compress Images Without Losing Visible QualityShrink image files for faster sites and smaller emails: the right format, quality and size to use, plus a free compressor that never uploads your photos.
- How to Convert Text Case Online (UPPERCASE, camelCase, More)Convert text into UPPERCASE, Title Case, camelCase, snake_case, kebab-case, CONSTANT_CASE and more at once, with real, verified examples of each.
- How to Count Words and Characters Online (and Hit Every Length Limit)How word, character, sentence and reading-time counts work, the length limits that matter, and a free counter that updates as you type.