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 is JSON and why does formatting matter?

JSON (JavaScript Object Notation) is the dominant data interchange format on the modern web. Created by Douglas Crockford in the early 2000s, it has replaced XML in most REST API contexts because it is lighter, more readable, and maps directly to data structures in virtually every programming language. Today, JSON is used in API responses, configuration files, database storage (MongoDB, CouchDB, PostgreSQL's JSONB), log files, and as a general-purpose data exchange format between services.

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.

API access

Format JSON programmatically via the Toolpad REST API:

POST https://api.toolpad.in/api/v1/datatools/format/json

Request body: {"input": "your json string", "indent": 2}

Is my JSON data sent to any server? +
No. This tool processes everything entirely in your browser using JavaScript. Your JSON is never transmitted to any server, stored anywhere, or seen by anyone. You can verify this by watching your browser's network tab โ€” no outbound requests are made when you format JSON.
What is the maximum file size this tool can handle? +
The formatter works well with JSON files up to approximately 5MB. Beyond that, browser memory constraints may cause slowdowns. For very large JSON files, consider using a command-line tool like jq or Python's json.tool module.
What is the difference between prettify and minify? +
Prettify adds indentation and line breaks to make JSON human-readable. Minify removes all whitespace (spaces, tabs, newlines) that is not inside string values, producing the most compact possible representation. Both operations preserve the exact data โ€” only the formatting changes.
Why does the validator say my JSON is invalid when it looks correct? +
The most common causes are: trailing commas (JavaScript allows them, JSON does not), single quotes instead of double quotes around strings or keys, unquoted property names, or a JavaScript-style comment. Also check for any characters that look like quotes but are actually typographic curly quotes (") which some text editors insert automatically.
Can I format JSON with comments (JSONC)? +
Standard JSON does not support comments. If your JSON file uses the JSONC format (JSON with Comments, used in VS Code settings files), you will need to remove the comments before pasting here. A future version may add JSONC support.