JSON Formatter

This JSON formatter (also called a JSON beautifier or pretty printer) indents pasted, dropped or opened JSON with 2 spaces, 4 spaces or tabs, or minifies it to one line. Invalid input shows the line and column of the error, and Repair fixes common mistakes such as trailing commas and single quotes.

Updated
Loading toolโ€ฆ

Format, repair and validate JSON.

How to use JSON Formatter

  1. Paste JSON, drop a .json file on the box, or click Open file (or Load sample to try it)
  2. Pick 2 spaces, 4 spaces or Tab, and tick Sort keys if you want keys Aโ†’Z
  3. Click Format (Ctrl/โŒ˜+Enter) to beautify, or Minify to compact it to one line
  4. If it's invalid, read the line and column, click Go to error, or use Repair & format
  5. Switch to Tree view to collapse nested data, then Copy or Download the result
Want the how & why?Read: What Is JSON? A Plain-English Guide for Non-Programmers โ†’
Try next โ†’CSV to JSONConvert CSV into JSON.

About JSON Formatter

A JSON formatter takes JSON that arrives as one dense line, such as an API response, a log entry or a config export, and prints it again with line breaks and indentation so you can see its structure. Paste it, drop a .json file on the box or click Open file, then click Format. Choose 2 spaces, 4 spaces or tabs for the indent, tick Sort keys to put object keys in Aโ†’Z order, and switch the result between a color-highlighted Code view and a collapsible Tree view. Minify does the reverse: it strips every optional space and line break to give the smallest one-line version.

It is also a JSON validator. Your browser's own JSON parser checks the input, so "Valid JSON" means the text follows the JSON grammar defined in RFC 8259 and ECMA-404. If it doesn't, you get the line and column of the first problem, a plain-English reason, the offending line with a caret under the spot, and a Go to error button that selects that character in the input box. A valid result also shows the input and output size, what the top level is (an object and its key count, or an array and its item count) and how deeply it nests. It checks syntax only, not whether the data matches a JSON Schema or what an API expects.

Most invalid JSON comes from a few mistakes: trailing commas, single quotes, unquoted keys, comments, Python's True, False and None, and files cut off part-way. Repair & format runs the open-source jsonrepair library, which fixes those and also straightens curly quotes, strips the ```json fences around JSON copied from an AI chat, removes JSONP wrappers such as callback({...}), and turns newline-delimited JSON into an array. Repair guesses at what you meant, so check the result before you rely on it.

Formatting changes whitespace, not values: strings, true, false, null and the order of array items mean exactly the same afterwards. Where your browser supports it, numbers are also kept exactly as written, so a 19-digit ID, 1.0 or 1e400 is not rounded or rewritten. Escapes may be spelled differently, because the text is printed again: "\u00e9" comes out as "รฉ" and "\/" as "/", which are the same strings. Two things do normalize, because the JSON is read into a JavaScript object first: a key repeated in one object keeps only its last value, and keys that are plain whole numbers, such as "2" and "10", print first in numeric order.

To pretty-print JSON in code instead: JSON.stringify(value, null, 2) in JavaScript; python -m json.tool data.json in a terminal (4-space indent by default) or json.dumps(data, indent=4) in Python; and jq . data.json (2 spaces by default). In VS Code, Format Document is Shift+Alt+F on Windows, Shift+Option+F on macOS and Ctrl+Shift+I on Linux.

Parsing and formatting happen in your browser. Pasted text and opened files are read locally and are not uploaded. The repair library is downloaded from this site as a script the first time you click Repair & format, then runs locally too. There is nothing to install and no sign-up.

Frequently asked questions

What does a JSON formatter do?
It takes JSON, often minified onto a single line, and prints it again with line breaks and indentation so the structure is easy to read and edit. JSON beautifier and JSON pretty printer are other names for the same thing. Only the layout changes; the keys and values stay the same (see "Does formatting change my data?" below for the details).
How do I check if my JSON is valid?
Paste it or open the file and click Format. Valid input shows โœ“ Valid JSON above the result. Invalid input shows the line and column of the first problem, a plain-English reason, the offending line with a ^ under the spot, and a Go to error button that selects that character in the input box. Your text stays in the box, so you can fix it by hand and format again, or click Repair & format to try an automatic fix.
How can I pretty print JSON?
Paste it here and click Format, or press Ctrl+Enter (โŒ˜+Enter on a Mac); pasting into the empty box formats it straight away. In code, use JSON.stringify(value, null, 2) in JavaScript or json.dumps(data, indent=4) in Python. In a terminal, python -m json.tool data.json and jq . data.json both print it indented.
How do I format a JSON file?
Click Open file, or drag the .json file onto the input box. It is read in your browser and formatted straight away, and Download .json saves the result as a new file named like data.formatted.json. In VS Code, open the file and run Format Document: Shift+Alt+F on Windows, Shift+Option+F on macOS, Ctrl+Shift+I on Linux.
Should I indent JSON with 2 spaces, 4 spaces or tabs?
All three are valid JSON. RFC 8259 allows space, tab, line feed and carriage return as insignificant whitespace between tokens, so every parser reads them the same way. Python's json.tool indents with 4 spaces by default and jq with 2. Follow whatever your project or style guide already uses; this page remembers your choice in this browser.
What is the difference between Format and Minify?
Format prints the JSON with line breaks and your chosen indent, one value per line, for reading and editing. Minify removes every optional space and line break to give the smallest single-line version, which is what you would send over a network or store. Both hold the same data, and the size boxes show the byte count before and after.
Does sorting keys change my JSON?
Not its meaning. RFC 8259 defines an object as an unordered collection of name/value pairs, so {"b": 1, "a": 2} and {"a": 2, "b": 1} are the same object. Sort keys reorders object keys at every level by character code, so capital letters come before lowercase ones. Arrays are never reordered, because their order is part of the data. One quirk: keys that are plain whole numbers, such as "2" and "10", always print first in numeric order, because that is how JavaScript orders object keys.
What does Repair & format fix?
It runs the open-source jsonrepair library, which adds missing commas, quotes and closing brackets; removes trailing commas; turns single and curly quotes into double quotes; strips // and /* */ comments; replaces Python's None, True and False with null, true and false; strips ```json code fences, JSONP wrappers such as callback({...}) and MongoDB types such as NumberLong(2); repairs truncated JSON; and turns newline-delimited JSON into an array. The result is then formatted. Repair guesses at intent, so check the output.
Does formatting change my data?
It shouldn't change any values. Where your browser supports it (JSON.rawJSON), numbers are kept exactly as written, so 1.0 stays 1.0 and a 19-digit ID keeps every digit. Without that support, for inputs over about 20 MB, and for extremely deep nesting (about 2,000 levels or more in Chrome), numbers are read as standard JavaScript numbers: integers above 9,007,199,254,740,991 can be rounded, 1.0 prints as 1, and a number too large to store, such as 1e400, becomes null. You get a warning when long numbers may have been rounded or a number was turned into null. In every browser, a key repeated in one object keeps only its last value; RFC 8259 says the names within an object SHOULD be unique.
Does it validate against a JSON Schema?
No. It checks syntax only: whether the text is well-formed JSON. It can't tell you whether required fields are present or values have the types a JSON Schema or an API expects; use a schema validator for that.
Does it have a tree view?
Yes. After formatting, switch the result from Code to Tree to browse the data as a collapsible outline. Objects and arrays expand and collapse and show how many keys or items they hold, and array items show their index. The top level starts expanded, and so do the objects and arrays directly inside it when the top level has 50 or fewer keys or items; deeper levels start collapsed. Expand all and Collapse all open or close everything at once. The tree view is turned off for documents with more than 20,000 values to keep the page responsive.
Does it accept comments or NDJSON?
Format doesn't, because strict JSON allows neither: a comment is reported as an error, and a second document after the first is reported as extra content after the JSON value. Repair & format handles both. It strips // and /* */ comments, and it turns newline-delimited JSON (one object per line) into a single JSON array.
Do I need a Chrome extension or plugin to use it?
No. It is a web page, so there is nothing to install โ€” no Chrome extension, add-on or plugin. Bookmark it and paste your JSON whenever you need it, in any browser.
How large a document can it handle?
There is no fixed size limit; the practical limit is your browser's memory, because everything runs in one tab. To keep big documents usable, color highlighting switches off when the output is over 500,000 characters, the tree view is off above 20,000 values, and the result sits in its own scrolling box instead of stretching the page. Minify is lighter than Format for very large files.
Is it safe to paste a real API response?
The JSON is parsed by your browser's own JSON engine and is not sent anywhere, and files you open are read locally the same way. The repair library is downloaded from this site as a script and then runs locally, so production payloads and any tokens inside them stay on your machine.