About the JSON Formatter
The JSON Formatter turns compact or messy JSON into clean, indented text that is easy to read, and it tells you when the JSON is not valid. JSON (JavaScript Object Notation) is the most common format for REST APIs, configuration files, NoSQL documents and log events. A single-line API response with hundreds of nested fields is almost impossible to scan by eye; once it is formatted, you can see every object, array and value at a glance and spot the field you are looking for in seconds.
How to Use the JSON Formatter
- Copy the JSON from your API client, browser network tab, log file or config file.
- Paste it into the input box above.
- Click Format. Valid JSON is re-printed with consistent indentation.
- If the JSON is invalid, read the error message to find the line and character that broke parsing.
- Use the copy button to put the formatted result back on your clipboard.
Common JSON Errors and How to Fix Them
Most parse errors come from a handful of mistakes. Trailing commas such as {"a": 1,} are allowed in JavaScript but not in JSON. Single quotes are invalid; keys and strings must use double quotes. Unquoted keys like {name: "Ali"} also fail. Comments (// or /* */) are not part of the JSON standard, and special values like undefined, NaN or Infinity are not allowed either. Fix the first error the formatter reports, then format again, because one mistake often causes several follow-on errors.
Formatted vs Minified JSON
Formatted (pretty-printed) JSON is for humans: it uses line breaks and indentation so you can review and edit it. Minified JSON removes all unnecessary whitespace so the payload is as small as possible, which is what you want to send over the network or store in a database column. Both contain exactly the same data. A good workflow is to keep pretty JSON in source control for configuration files, and let your application serialize minified JSON at runtime.
Example
Input: {"user":{"id":42,"roles":["admin","editor"],"active":true}}. After formatting, user appears on its own line, id, roles and active are indented beneath it, and each role sits on a separate line inside the array. Now it is obvious that roles is an array and active is a boolean, not a string.
Frequently Asked Questions
Is my JSON data safe?
Your input is only used to produce the formatted output and is not published. Even so, as with any online tool, avoid pasting production secrets such as API keys, passwords or personal customer data.
Why does valid JavaScript fail as JSON?
JSON is a strict subset of JavaScript object syntax. Single quotes, trailing commas, comments and unquoted keys are fine in JavaScript code but are rejected by a JSON parser.
Can I format very large JSON files?
Yes, typical API responses and config files format instantly. For files of many megabytes a desktop editor or a command-line tool such as jq may be more comfortable.
What indentation does the formatter use?
It uses a consistent indentation for every nesting level, which matches the style most editors and API tools use by default.