JSON formatter & validator
Prettify, minify, and validate JSON instantly in your browser. Syntax errors are detected and reported with the exact line and character position. Choose from 2-space, 4-space, or compact indentation. All processing happens locally — your data never leaves your machine.
Input JSON
Output
What this JSON formatter does
The JSON formatter checks JSON text, prettifies it with indentation, or minifies it into one line. When the JSON is invalid, it reports the error with its line number, so you can find the mistake quickly. Everything runs in your browser.
How to use it
- Paste your JSON into the input box.
- Click Prettify JSON to indent it, Minify to remove whitespace, or Validate only to check it without changing it.
- Copy or download the result, or clear the box to start again.
Common JSON errors
- Trailing commas: JSON does not allow a comma after the last item in an object or array.
- Single quotes: JSON strings must use double quotes.
- Unquoted keys: every key must be a quoted string.
- Comments: JSON has no comment syntax, so remove
//and/* */comments before validating.
Formatting, minifying and validating
Prettifying changes only whitespace, so the data is the same before and after. Minifying removes the whitespace, which makes the payload smaller for APIs and config files. Validating checks the syntax against the JSON standard (RFC 8259). It does not check the data against a schema, so a valid document can still have the wrong fields.
Privacy
JSON you paste is processed in your browser. It is not stored or sent to Toolpad's servers. Remove sensitive values such as tokens and passwords before you share a formatted result with anyone.
Related tools
To turn plain key-value text into JSON, use the Text to JSON converter. To convert JSON into XML, use the JSON to XML converter. For encoding a JSON string for a URL, see the URL encoder.
What is JSON and why does formatting matter?
Raw JSON from APIs and services is often compact — all whitespace is removed to reduce payload size. This is ideal for network transmission but completely unreadable when you need to inspect or debug the data. A formatter adds consistent indentation and line breaks to transform a wall of text into a structured, readable document while preserving the exact data content.
How this JSON formatter works
This tool uses the browser's native JSON.parse() and JSON.stringify() functions to process your JSON. Parsing validates the syntax and builds an in-memory representation of the data structure. Stringify then serialises it back to text with the specified indentation level. This approach has several advantages: it is extremely fast even for large JSON documents, it always produces standards-compliant output, and it normalises the JSON (fixing minor inconsistencies in spacing around colons and commas).
For error reporting, when JSON.parse() fails it throws a SyntaxError with a message that includes the position of the error. This tool parses that error message to report the exact line and character where the problem was found, making it much faster to locate and fix syntax issues than manually searching through a large document.
JSON formatting best practices
For human-readable configuration files and documentation, 2-space indentation is the most widely adopted standard — it is used by npm, Google's style guide, and most linting tools. 4-space indentation is common in Python-influenced projects and provides slightly more visual separation at the cost of line length. Compact (minified) JSON is appropriate for production API responses and any context where bandwidth matters. Never use tab indentation in JSON files shared between different editors and systems — tab width varies by environment and can cause visual inconsistencies.
Common JSON syntax errors and how to fix them
The most frequent JSON errors developers encounter are: trailing commas after the last item in an object or array (valid in JavaScript but invalid in JSON), single-quoted strings (JSON requires double quotes), unquoted property names (also valid in JavaScript but invalid in JSON), comments (JSON has no comment syntax), and special characters in strings that need to be escaped with a backslash. If this formatter reports a syntax error, check the indicated line for these common mistakes first.
Request body: {"input": "your json string", "indent": 2}