How to Format and Validate JSON
October 9, 2026 · 4 min read
To format and validate JSON, paste the document into a parser-based formatter and run Format. Valid input becomes consistently indented; invalid input should produce an error with a line and column. Fix that location, run the check again, and repeat until the parser accepts the entire document.
The JSON formatter and validator performs those steps in your browser. You can choose two spaces, four spaces, or tabs, optionally sort object keys, then copy or download the result. It also minifies valid JSON when compact transfer or storage matters more than readability.
What valid JSON requires
JSON has a small grammar, but it is stricter than a JavaScript object literal. The top level can be an object, array, string, number, boolean, or null. Objects use braces and contain comma-separated name-value pairs; arrays use brackets and contain comma-separated values.
Every object key must be a double-quoted string. String values also use double quotes, and a quote inside a string must be escaped. Valid values are strings, finite JSON numbers, objects, arrays, true, false, or null. Undefined, functions, dates, and special numeric values such as NaN are not JSON values.
Whitespace can appear between tokens, which is why compact and beautified documents represent the same parsed data. Encoding text as UTF-8 is the safest common choice when moving JSON between systems.
The most common JSON syntax errors
Most invalid documents fail because syntax from JavaScript, configuration languages, or casual notation slips into JSON. Look just before the reported location as well as at it, because a missing delimiter can make the parser complain at the next token.
A trailing comma is invalid: {"name":"Ada",}. Remove the comma after the final member. Single quotes are invalid: {'name':'Ada'}. Replace them with double quotes. Unquoted keys are invalid: {name:"Ada"}. Write {"name":"Ada"} instead.
Comments are not part of JSON. Both // note and /* note */ must be removed or stored as ordinary string data. Other frequent problems include missing commas between members, mismatched braces or brackets, raw line breaks inside strings, and backslashes that do not begin a valid escape sequence.
- Trailing comma: remove the comma before a closing brace or bracket.
- Single quotes: use double quotes around keys and string values.
- Unquoted key: put every object property name in double quotes.
- Comment: remove it because standard JSON has no comment syntax.
- Broken string: escape an internal quote and any literal backslash.
How to read line and column errors
A line and column message is a starting point, not always the origin of the mistake. If line 12 begins a new key but line 11 lacks a comma, the parser may point at line 12 because that is where continuing became impossible.
Go to the reported line, inspect the indicated character, and then scan backward to the preceding value or delimiter. Check quote pairing, commas, and nesting. When the message appears at the end of the file, an earlier object, array, or string may never have been closed.
The formatter shows the failing source line with a caret under the calculated column. Correct one error at a time and rerun validation; after the first structural issue is fixed, a later issue may become visible.
Beautify, minify, and sort keys for different jobs
Beautifying adds indentation and line breaks so you can understand hierarchy during debugging, review, and manual editing. Two spaces produce a compact readable result; four spaces create stronger visual nesting; tabs follow editor preferences without changing the data model.
Minifying removes optional whitespace. It is suitable for transport, embedded fixtures, or storage where people do not need to read the file directly. Minification is not compression and it does not hide sensitive values. Anyone receiving the document can beautify it again.
Sorting keys alphabetically can make object structures easier to scan and can reduce noisy differences between versions. It changes object key order but leaves associated values and array item order intact. Do not use it when a consumer incorrectly relies on presentation order, and remember that arrays are intentionally ordered.
How to format and validate JSON with Tools on Deck
Use this sequence when you receive an API response, configuration export, or hand-edited document. Validation runs as you work, while the Format and Minify actions create an output you can copy or save.
- Paste JSON into the Input editor, or use Open file to load a local JSON or text file.
- Read the validity message; if it is invalid, go to the reported line and column and repair the syntax.
- Choose 2 spaces, 4 spaces, or Tab, and enable Sort keys only when you want alphabetical object keys.
- Select Format to create readable output, then review the nesting and values.
- Select Minify instead when you need valid compact JSON without optional whitespace.
- Copy the output or download the generated formatted or minified JSON file.
Compare two JSON versions without noise
When two JSON documents differ, format both with the same indentation and key-sorting choice before comparing them. Consistent layout prevents harmless whitespace and property-order changes from burying the value changes you need to review.
Paste the normalized versions into the diff checker. Line mode works well for formatted objects and offers split or unified views. You can also compare by words or characters, and ignore case or whitespace when those differences are not relevant.
For JSON embedded in a larger JavaScript, TypeScript, YAML, or GraphQL file, use the code formatter with the correct language selected. A formatter can expose structure, but it does not prove that application-specific fields, types, or required values are correct.
Quick answers about JSON formatting
Does formatting change JSON data? Indentation alone does not; sorting changes object key presentation but not each key’s value. Does validation confirm the data is correct for an API? It confirms JSON syntax, not a business schema unless a separate schema validator is involved.
If a document fails, start at the reported line and column, inspect the token before it, and look for commas, quotes, comments, or unclosed nesting. Once it parses, beautify for people, minify for compact transfer, and compare normalized copies when reviewing changes.