JSON Formatter & Validator
Format, beautify, validate, or minify JSON online. Indent nested objects, sort keys, and convert minified JSON into a readable format. Invalid JSON is reported with its line and column location.
Tip: Click in the JSON and copy (Ctrl/Cmd+C) to copy the path at the caret (object►glossary►GlossDiv). The Copy button still copies the formatted JSON.
What is JSON?
JSON (JavaScript Object Notation) is a plain-text format for structured data, standardised in RFC 8259 and ECMA-404. A JSON document is built from objects ({} with string keys), arrays ([]), double-quoted strings, numbers, true, false and null. It is the usual payload format for REST APIs and is common in configuration files, logs and document databases. The grammar is deliberately small: no comments, no trailing commas, no single-quoted strings and no unquoted keys, which is why hand-edited JSON fails to parse more often than you might expect.
How to use the JSON formatter
- Paste JSON into the Input pane, or load it with File (a file on your computer) or URL (your browser fetches the address directly, so the remote server must allow cross-origin requests).
- Pick an Indent of 2 spaces, 4 spaces or Tab, and tick Sort keys (A-Z) if you want keys in a stable order.
- Click Beautify for indented output or Minify for a single line. Validate only checks the input and shows "Valid JSON" if it parses.
- Browse the structure with Tree Viewer, then use Copy or Download.
Buttons and options explained
- Beautify parses the input with the browser's built-in
JSON.parseand writes it back withJSON.stringifyusing the chosen indent. Every object member and every array element goes on its own line. - Minify does the same parse and writes the value with no whitespace at all.
- Validate parses without changing the output. Errors are shown above the panes.
- to XML converts objects to elements, repeats the element name for each array item and turns keys that start with
-into attributes. An object with a single key becomes the root element; other objects and arrays are wrapped in<root>. For more control, use the JSON to XML converter. - to CSV flattens nested objects into dotted column names such as
address.cityandtags.0, unwraps a single-key wrapper like{"items": [...]}and builds the header from every key it finds. It ignores Sort keys and Indent. - Sort keys (A-Z) sorts object keys at every level; arrays keep their order. Keys are compared by character code, so capitals sort before lower case (
Zetabeforealpha), and integer-like keys such as"2"and"10"always come first in numeric order, because that is how JavaScript orders object properties. It applies to Beautify, Minify and to XML. - Indent applies to Beautify and to XML.
- Tree Viewer shows the Input as a collapsible tree and updates as you type. Clicking a node copies its path, for example
object►users►0►name. Beautify, Minify, to XML and to CSV switch the Output pane back to text; click Tree Viewer to return. - Download saves the output as
formatted.json, or asconverted.xmlorconverted.csvafter a conversion.
What re-serialising changes
Because the formatter parses your JSON and prints the parsed value, the output is not always a character-for-character reindent of the input:
- Duplicate keys collapse to the last value:
{"a":1,"a":2}becomes{"a":2}. RFC 8259 says names should be unique and leaves other behaviour to the parser. - Integers larger than 253 lose precision:
12345678901234567890is printed as12345678901234567000. Send large IDs as strings. - Numbers are normalised:
1.0becomes1and1e3becomes1000. - Unicode escapes are decoded:
"é"is printed as"é".
Common errors and how to fix them
Invalid input is reported above the panes with the prefix "Invalid JSON:", and the Output pane shows "Not valid". The wording comes from your browser's JSON parser, so it differs between browsers. When the message contains a character position, the tool adds the line and column so you can jump to the problem. The JSON syntax errors guide covers each case in more depth.
| Input | Cause | Fix |
|---|---|---|
{"a":1,} | Trailing comma after the last member or element | Delete the final comma |
{'a':1} | Single-quoted string or key | Use double quotes |
{a:1} | Unquoted key (valid in JavaScript, not JSON) | Quote the key: {"a":1} |
{"a":1 // note} | Comments are not part of JSON | Remove // and /* */ comments |
{"a":1 | Missing comma between members | Add a comma at the end of the line before the reported position |
{"a":01}, NaN | Leading zeros, NaN, Infinity and undefined are not JSON values | Write 1, or use null or a string |
A literal line break inside "..." | Control characters must be escaped in strings | Use \n or \t |
{"a":1}{"b":2} | More than one value, e.g. JSON Lines | Wrap the values in an array, or format one line at a time |
Examples
| Input | Action | Output |
|---|---|---|
{"id":1,"tags":["a","b"]} | Beautify, 2 spaces | { |
{"b":2,"a":1} | Minify with Sort keys (A-Z) | {"a":1,"b":2} |
{"z":{"b":1,"a":2},"list":[{"y":1,"x":2}]} | Minify with Sort keys (A-Z) | {"list":[{"x":2,"y":1}],"z":{"a":2,"b":1}} |
{"order":{"-id":"42","item":"Pen","qty":2}} | to XML | <order id="42"> (after an XML declaration) |
[{"id":1,"address":{"city":"London"}},{"id":2,"address":{"city":"Leeds"}}] | to CSV | id,address.city |
Frequently asked questions
Is my JSON uploaded anywhere?
No. Parsing, formatting, conversion and the tree view all run in JavaScript in your browser, and the page does not send your input to a server. The only network request involving your data is the one you trigger with the URL button, which your browser makes directly to the address you enter.
What is the difference between Beautify and Minify?
Both produce the same data. Beautify adds line breaks and indentation for reading and reviewing; Minify removes all whitespace, which is the compact form you would normally send over an API or store.
Why is there no line number in my error message?
The tool can only add a line and column when the browser's error message includes a character position. Some messages, such as the one for a trailing comma inside an array in Chrome, quote the input instead, so look for the token named in the message.
Can it format JSON with comments (JSONC or JSON5)?
No. The formatter uses the standard JSON parser, so comments, trailing commas and unquoted keys are reported as errors. Remove them first; the output is then strict JSON that any parser accepts.
Does sorting keys change the meaning of my JSON?
Not for standard JSON: RFC 8259 defines objects as unordered collections, so key order carries no meaning. Sorting is useful before comparing two documents in the Diff Checker. Array order is never changed.
How do I copy the path to a value?
Click the node in Tree Viewer, or place the caret inside the value in the Input or Output pane and press Ctrl+C (Cmd+C on a Mac) without selecting text. The path, such as object►glossary►GlossDiv, is copied and shown in the path bar.
Guides
Common JSON Syntax Errors and How to Fix Them
Trailing commas, single quotes, comments, unescaped characters and other reasons JSON fails to parse, with the error each one produces and the fix.
How to Pretty-Print JSON in JavaScript, Python, jq and VS Code
Format JSON with indentation from the command line, in code and in your editor: JSON.stringify, python -m json.tool, jq and VS Code.
JSON vs YAML vs XML: Differences and When to Use Each
How JSON, YAML and XML differ in syntax, data types, comments, schemas and tooling, and which to choose for APIs, configuration and documents.