JSON Formatter: beautify, minify and validate JSON online

Input

Output

What is JSON?

JSON (JavaScript Object Notation) is the format most of the internet uses to move structured data around. An API response, a configuration file, a log line, the body of a webhook: all of it is usually JSON, because the format is small enough to describe in a page and every language can read it.

A JSON document holds exactly one value. That value is usually an object (a set of double-quoted keys and their values, wrapped in braces) or an array, but it can equally be a single string, number, true, false or null. There are no comments, no trailing commas, no single quotes and no unquoted keys, which is the source of most of the errors this tool reports.

Why use a JSON formatter?

JSON is written for machines, and machines send it as one long line. A formatter turns that back into something a person can read, and along the way tells you whether it is valid at all:

  • Readability. Indentation turns a wall of braces into a shape you can scan: which keys sit at the top level, what is nested inside what, where an array ends.
  • Debugging. An API response that “does not work” is often a missing comma or an unclosed bracket. The error here names the line and column, so you look at one character instead of re-reading the whole payload.
  • Size. Minifying does the reverse and strips every space and line break, which is what you want before putting a document in an environment variable, a URL or a request body.

Example

Minified, as an API sends it
{"id":42,"name":"Gradient Learnings","tags":["sql","python"],"active":true,"score":9.5}
Beautified
{
  "id": 42,
  "name": "Gradient Learnings",
  "tags": [
    "sql",
    "python"
  ],
  "active": true,
  "score": 9.5
}

With Inline Short Objects set to 60, small arrays and objects that fit inside that width stay on one line. That is a middle ground between the two, and usually the most readable of the three:

Beautified, inline width 60
{
  "id": 42,
  "name": "Gradient Learnings",
  "tags": ["sql", "python"],
  "active": true,
  "score": 9.5
}

About Gradient Learning's JSON Formatter

It is free, needs no sign-up, and runs entirely in your browser: the document you paste is never uploaded, stored or logged, and the page keeps working if you go offline after it loads. That matters more for JSON than for most formats: the thing people most often need to read is an API response, and an API response tends to have somebody's personal data or an access token in it.

It also does not use the browser's built-in JSON.parse to do the work, which is what most online formatters are. That shortcut has three consequences worth knowing about, because it means a formatter can change your data:

  • Long numbers are rounded. An id like 12345678901234567890 does not fit in a JavaScript number, so it comes back as 12345678901234567000. Here a number is copied across as you wrote it, digit for digit.
  • Numeric keys are reordered. A JavaScript object always lists keys like “2” and “10” first and in numeric order, whatever order the file had them in. Here the file's order is kept unless you ask for sorting.
  • Duplicate keys disappear silently. This tool leaves them alone and shows you both, unless you turn on Merge Duplicate Keys.

How to use the tool

  1. Paste your JSON into the input panel on the left.
  2. The formatted document appears in the output panel on the right as you type. There is nothing to click. If it cannot be parsed, a strip across the top of the output names the problem and its line and column; press the position to jump the cursor to it.
  3. Switch between Beautified and Minified, set the indentation, then use the copy or download button on the output panel.

Formatting options

Basic options (always visible)

OptionWhat it controlsPossible values
OutputWhether to expand the document or strip it to one lineBeautified, Minified
IndentationWidth of one indent level in the beautified output2, 3 or 4 spaces, Tabs
Sort KeysOrder of the keys in every object, nested ones included. Values are never reordered.Original order, A → Z, Z → A

Advanced options (under “More”)

OptionWhat it controlsPossible values
Inline Short ObjectsObjects and arrays whose one-line form fits in this many columns are kept on one line0–200 (0 turns it off, which is the default)
Allow CommentsAccepts // and /* */ in the input. JSON has no comments, so they are dropped from the outputOn, Off
Allow Trailing CommasAccepts a comma before a closing bracket. The output never has oneOn, Off
Merge Duplicate KeysKeeps the last value of a repeated key, at the position the key first appearedOn, Off
Escape Non-ASCIIRewrites accented and non-Latin characters as \uXXXX escapesOn, Off

Frequently asked questions

Is the Gradient Learning JSON Formatter safe to use?

Yes. It runs entirely in your browser, so the document you paste is never uploaded, stored or logged, and the page keeps working if you go offline after it loads. That is worth knowing for JSON in particular: the thing people most often need to read is an API response, and those tend to carry personal data or an access token.

Does it validate my JSON as well as format it?

Yes. Formatting a document requires parsing it, so anything that formats is valid JSON. When it is not, you get one sentence saying what is wrong, the line and column of the character that caused it, and a squiggle under that character in the editor. The last output that worked stays on screen, so you do not lose your place while you fix it. If checking is the whole job, the JSON Validator shares this parser and reports in more detail: the failing line in context, and any duplicate keys.

Why did my JSON fail to parse?

The four usual causes are a trailing comma before a closing bracket, single quotes instead of double quotes, an unquoted key, and a bracket that was never closed. Comments are a fifth: JSON has none, however normal they look in a config file. Comments and trailing commas can both be accepted under More if that is what your file has.

Will formatting change my data?

No. Numbers keep the exact digits you wrote, key order is preserved, escapes inside strings are left as they are, and duplicate keys are passed through. Three options do change something, and all three are off by default: Sort Keys reorders keys, Merge Duplicate Keys drops all but the last value of a repeated key, and Escape Non-ASCII rewrites accented characters as \uXXXX escapes.

Can it handle very long numbers?

Yes, and this is where most online formatters quietly fail. They run your document through the browser's JSON.parse, which turns every number into a floating-point double, so an id like 12345678901234567890 comes back as 12345678901234567000, and 1e-400 becomes 0. This tool copies a number across as source text, so what you paste is what you get.

What is the difference between beautifying and minifying?

They are the two directions of the same operation. Beautifying adds line breaks and indentation so a person can read the document; minifying removes every space and line break so it takes as few bytes as possible. Neither changes what the document means, so you can go back and forth as often as you like.

Can I sort the keys?

Yes: A → Z or Z → A, applied to every object in the document including nested ones. Sorting is by character code, so uppercase letters sort before lowercase ones, and the order does not depend on your browser's language. Array items are never reordered: their order is part of the data.

Is there a size limit?

Not on what you paste, but a file you open has to be under 1 MB. Past that the editor itself becomes slow, which is a worse experience than being told no. The parsing runs in a background thread, so a large document does not freeze the page while it works.