JSON Formatter
Format, validate, and minify JSON instantly
What is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format that has become the lingua franca of web APIs, configuration files, and data storage. Defined by Douglas Crockford in the early 2000s and formalized in RFC 8259, JSON represents structured data using two universal constructs: ordered lists (arrays) and key-value maps (objects). Its syntax is a strict subset of JavaScript, which made it immediately familiar to web developers and easy to parse in every programming language.
Despite its simplicity, JSON in the wild is often difficult to read. API responses arrive as dense, single-line strings to save bandwidth. Minified config files sacrifice readability for compactness. Hand-edited JSON accumulates inconsistent indentation. A JSON formatter solves these problems by parsing the data and re-serializing it with consistent, configurable whitespace — transforming an impenetrable wall of text into a clearly indented structure you can scan in seconds.
Beyond cosmetic improvement, formatting is a debugging tool. When a JSON payload fails to parse, a good formatter pinpoints the exact character where the syntax breaks — an unescaped quote, a missing comma, a trailing comma that the strict spec forbids. This turns what could be minutes of manual scanning into an instant diagnosis.
How it works
JSON formatting is a two-phase process: parsing and serialization. The parser reads the input string character by character, building an in-memory tree of objects, arrays, strings, numbers, booleans, and null values. If the input violates JSON syntax at any point — an unquoted key, a single quote instead of double, a trailing comma — the parser throws an error identifying the exact line and column where it failed.
Once the parser has produced a valid in-memory representation, the serializer walks the tree and emits a new string with the chosen formatting options applied. For pretty-printing, it inserts newlines after each key-value pair and array element, adds indentation (typically two or four spaces per nesting level), and places opening and closing braces on their own lines. For minification, it strips all optional whitespace, producing the most compact valid representation.
This tool uses the browser's native JSON.parse() for parsing, which is implemented in optimized C++ inside the JavaScript engine and handles payloads of several megabytes without difficulty. The serialization step uses JSON.stringify() with a configurable space argument for indentation. Because both operations are built into the engine rather than implemented in JavaScript, performance is excellent even for large inputs.
How to use this tool
- Paste your raw JSON into the input area. The tool accepts any valid JSON — objects, arrays, strings, numbers, or primitive values.
- Click "Format" to pretty-print the JSON with consistent indentation, or "Minify" to strip all whitespace for a compact single-line output.
- If the JSON is invalid, an error message will appear indicating the line and character position where parsing failed. Fix the syntax error in the input and try again.
- Use the copy button to copy the formatted or minified output to your clipboard for use in your editor, API client, or configuration file.
- Adjust the indentation level (2 or 4 spaces) using the settings control if your project has a specific formatting convention.
Examples
Pretty-printing a minified API response
API responses are often delivered as a single line like {"users":[{"id":1,"name":"Alice"},{"id":2,"name":"Bob"}]}. Pasting this into the formatter produces a cleanly indented structure with each key-value pair on its own line, making it easy to inspect the data shape and spot unexpected values.
Debugging a JSON syntax error
If you paste {"name": "Alice", "age": 30,} (note the trailing comma), the formatter reports an error at the exact position of the trailing comma. JSON's strict spec does not allow trailing commas, and the formatter pinpoints the issue immediately rather than leaving you to scan the input manually.
Minifying JSON for a config deployment
A 200-line JSON configuration file can be minified to a single line for embedding in environment variables or reducing payload size in network requests. The minified output preserves all data exactly while removing every byte of unnecessary whitespace.
Comparing two JSON objects by normalizing formatting
When two JSON objects have different indentation or key ordering in the source text, formatting both with the same settings produces consistent output that can be compared with a diff tool. This is useful for verifying that a refactored API still returns the same data structure.
About this tool
Paste any JSON to format it with syntax highlighting, validate structure, minify for production, or convert between JSON and other formats. Handles large payloads efficiently.
Common use cases
- • Pretty-printing minified JSON from API responses for easier reading and debugging
- • Validating JSON payloads before sending them to an API or saving to a config file
- • Minifying JSON for production use to reduce payload size
- • Quickly checking JSON syntax when editing configuration files by hand
Frequently asked questions
- What happens if my JSON is invalid?
- The formatter will highlight the syntax error and show the line and position where parsing failed, helping you quickly locate and fix the issue.
- Can this tool handle large JSON files?
- Yes. The formatter processes JSON entirely in your browser and handles payloads up to several megabytes efficiently. For very large files, consider using a streaming JSON parser instead.
- Does formatting change the data?
- No. Formatting only adds or removes whitespace and indentation. The actual data values, structure, and key ordering remain unchanged.
- What indentation style should I use for JSON?
- Two spaces and four spaces are the most common conventions. Two spaces keep deeply nested structures compact and are the default in many JavaScript projects and npm package.json files. Four spaces are common in Python ecosystems and are easier to read for shallow structures. Tabs are valid but rarely used in JSON because JSON is often embedded in contexts that assume space indentation.
- Why does JSON not allow trailing commas?
- The JSON specification (RFC 8259) requires strict syntax — trailing commas after the last element in an array or object are not permitted. This differs from JavaScript, which tolerates them. If you paste JSON with trailing commas, the formatter will flag it as a syntax error and indicate the exact position, helping you remove the offending comma.
- Can I use comments in JSON?
- Standard JSON does not support comments of any kind — no // line comments and no /* block comments */. This is by design to keep the format simple and unambiguous for machine parsing. If you need comments, consider JSONC (JSON with Comments, used by VS Code configs), JSON5, or YAML. The formatter strictly validates against the JSON specification.