JSON Formatter
Format, validate, and minify JSON data
Input JSON
Output
📖 What is JSON?
JSON (JavaScript Object Notation) is a lightweight data-interchange format that's easy for humans to read and write and easy for machines to parse and generate.
- • Uses key-value pairs
- • Supports strings, numbers, booleans, arrays, objects
- • Language-independent format
- • Widely used in APIs and config files
💡 Common Uses
- • API request/response formatting
- • Configuration files
- • Data storage and transfer
- • Web service communication
- • Debugging API responses
- • Database document storage
Overview
The JSON Formatter beautifies, minifies and validates JSON (JavaScript Object Notation), the text format used by most web APIs and many configuration files. Paste a compressed API response and it becomes an indented, readable structure; paste readable JSON and it can be squeezed onto a single line for transfer or storage.
The page parses your input with the browser's built-in JSON parser, which follows the JSON standard (RFC 8259 and ECMA-404), and then re-serializes it. Format/Beautify indents nested objects and arrays by 2, 4 or 8 spaces; Minify removes all unnecessary whitespace; Validate Only confirms the input parses without changing it. When parsing fails, the browser's error message is shown, which usually points to the position of the problem.
Because the data is re-serialized, a few details can change: duplicate keys keep only the last value, and integers larger than 9,007,199,254,740,991 lose precision. All processing happens locally in your browser.
How to Use
- Paste your JSON into the Input JSON box, or click Load Sample to try an example object.
- Choose an indent size from the Indent menu: 2 spaces, 4 spaces or 8 spaces.
- Click Format/Beautify for readable, indented output, Minify for compact single-line output, or Validate Only to check the syntax.
- If the input is invalid, read the red error box for the parser's message, fix the problem in the input and try again.
- Click the copy icon above the Output box to copy the result.
Frequently Asked Questions
Why is my JSON invalid?
The most common causes are single quotes instead of double quotes around strings or keys, a trailing comma after the last item in an object or array, unquoted keys, comments, and values like undefined or NaN that JSON does not allow. These are all valid in JavaScript but not in strict JSON. The error box shows the parser's message, which usually includes the position where parsing stopped.
What is the difference between beautifying and minifying JSON?
Beautifying adds line breaks and indentation so people can read the structure. Minifying removes every space and line break that is not inside a string, producing the smallest possible text for sending over a network. Both contain exactly the same data. For example, {"a":1,"b":[true,null]} is the minified form; beautified with 2 spaces, each key, array item and closing bracket goes on its own line.
Should I use 2 or 4 spaces to indent JSON?
Either is correct, because whitespace outside strings has no meaning in JSON. Two spaces is the common default in JavaScript projects and keeps deeply nested data narrow; four spaces is popular in Python projects and can be easier to scan. Pick whatever matches your team's style or editor settings. The 8-space option is useful mainly for very shallow data or presentations.
Does the formatter change my data?
Values are preserved for normal JSON, but there are edge cases. If an object has the same key twice, only the last value is kept. Numbers are converted to JavaScript numbers, so an integer such as 12345678901234567890 becomes 12345678901234567000 and 1.0 becomes 1. If you handle large IDs, store them as strings. Key order and string contents are kept as they are.
Is it safe to paste sensitive JSON into this tool?
The page parses and formats JSON with your browser's own JavaScript engine and does not upload the input. Even so, treat secrets carefully: avoid pasting live API keys, access tokens or personal data into any web tool on a shared or untrusted computer, and remove credentials from logs before sharing formatted output with others.
Can this tool fix or convert JSON5, YAML or XML?
No. It accepts strict JSON only and reports anything else as invalid. JSON5 features such as comments, single quotes and trailing commas must be removed first, and YAML or XML need a dedicated converter. The tool also does not validate against a JSON Schema; Validate Only checks syntax, not whether the data has the fields your application expects.