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.

Indent:
Copied
Input0 B
Output0 B

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

  1. 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).
  2. Pick an Indent of 2 spaces, 4 spaces or Tab, and tick Sort keys (A-Z) if you want keys in a stable order.
  3. Click Beautify for indented output or Minify for a single line. Validate only checks the input and shows "Valid JSON" if it parses.
  4. Browse the structure with Tree Viewer, then use Copy or Download.

Buttons and options explained

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:

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.

InputCauseFix
{"a":1,}Trailing comma after the last member or elementDelete the final comma
{'a':1}Single-quoted string or keyUse double quotes
{a:1}Unquoted key (valid in JavaScript, not JSON)Quote the key: {"a":1}
{"a":1 // note}Comments are not part of JSONRemove // and /* */ comments
{"a":1
"b":2}
Missing comma between membersAdd a comma at the end of the line before the reported position
{"a":01}, NaNLeading zeros, NaN, Infinity and undefined are not JSON valuesWrite 1, or use null or a string
A literal line break inside "..."Control characters must be escaped in stringsUse \n or \t
{"a":1}{"b":2}More than one value, e.g. JSON LinesWrap the values in an array, or format one line at a time

Examples

InputActionOutput
{"id":1,"tags":["a","b"]}Beautify, 2 spaces{
  "id": 1,
  "tags": [
    "a",
    "b"
  ]
}
{"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">
  <item>Pen</item>
  <qty>2</qty>
</order>
(after an XML declaration)
[{"id":1,"address":{"city":"London"}},{"id":2,"address":{"city":"Leeds"}}]to CSVid,address.city
1,London
2,Leeds

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

Related tools