JSON formatter

A JSON formatter takes minified API responses and config files and prints them back with clean, consistent indentation. This page formats JSON, checks it against RFC 8259, and converts it to YAML or CSV. It is free, there is no signup, and everything runs in your browser.

Last verified: November 14, 2026 · Primary source: RFC 8259 · Independent tool, not affiliated with the JSON project

Format JSON

The status line checks the document as you type and never changes your input. Live formatting runs for inputs under 300,000 characters; longer inputs wait for the Format button. Numbers are printed exactly as written, including 1.10 and integers with more than 15 digits.

What the formatter changes

  • Indentation. Every object and array gets one level per nesting depth, with 2 spaces, 4 spaces or a tab. One key-value pair per line, so a diff shows exactly what changed.
  • Minify. The reverse: every space and line break that carries no meaning is stripped, for the smallest payload to send over the wire or paste into an environment variable.
  • Key order. Left alone by default. Tick Sort keys A to Z when you need two documents to line up for a diff.
  • Numbers. Printed exactly as written. 1.10 stays 1.10 and 12345678901234567890 stays whole, where most browser formatters would print 1.1 and round the integer.
  • Strings. Escapes are normalised to the short form: a literal newline inside a string becomes \n, a tab becomes \t. The text itself is untouched.
  • Nothing else. Formatting never drops a key, renames anything, or reorders an array. If the output differs from the input in any other way, something is wrong.

What validation catches

Formatting doubles as validation: if the text does not parse, the page tells you exactly where it broke instead of failing quietly. The parser on this page is written for RFC 8259, the standard that defines JSON, and it checks four things most formatters skip.

Exact error position

Every error names a line and a column, and the message says what was expected. A trailing comma, an unclosed string, a missing colon after a key, a number written as 012: each gets its own plain sentence. The first error is shown; fix it and check again, because one mistake early on can hide the next one.

Duplicate keys

Two keys with the same name in one object are valid grammar, but most parsers keep only the last value and stay quiet. That is usually a copy-paste mistake: a config with two "port" entries runs on the second one and nobody notices. You get a warning with the line and column of the second key, and formatting keeps both in the output so you can see the pair.

Numbers that lose digits

JavaScript numbers are 64-bit floats. An integer past 9,007,199,254,740,991 (2 to the power of 53, minus 1) cannot be stored exactly, so JSON.parse rounds it before you ever see it. Snowflake IDs, 64-bit database keys and nanosecond timestamps all live past that line. The output keeps the original spelling, and a warning marks the exact position, so you know which value to treat as a string.

Document statistics

A valid document reports its shape: how many objects, arrays and keys it holds, and how deep the nesting goes. That is the fastest way to tell whether a 2 MB API response is one flat list or a tree five levels deep before you start querying it.

Common JSON errors

ErrorWhat it usually means
Trailing commaA comma after the last item in an array or object, usually from deleting an entry by hand. [1,2,3,] is not valid JSON. Delete the comma.
Single quotesJSON requires double quotes. Hand-written config and JavaScript object literals often use single ones. {'a':'b'} needs {"a":"b"}.
Unquoted keysA JavaScript-style key with no quotes at all. {a:1} needs {"a":1}.
CommentsJSON has no comments. // note and /* note */ both break the parser. Move the note into a field, or strip it before pasting.
Unterminated stringA quote opened but never closed on the same line. Strings cannot span lines; use \n inside the string.
Leading zeroA number written as 012. JSON forbids a zero followed by another digit. Write 12.
NaN, undefined, InfinityJavaScript values that are not JSON. {"x": NaN} needs null or a string. Python output has the same problem with True, False and None.
Text after the documentA second JSON value pasted after the first, or a log line stuck to the end. One document holds one value; wrap two in an array.

Five of these have a one-click fix. The Repair button handles trailing commas, single quotes, unquoted keys, comments and the non-JSON constants, and it lists every change it made. It never touches a document that already parses, and it only offers a result that itself parses as valid JSON.

Query with JSONPath

A large API response is easier to read one branch at a time. Switch the output to JSONPath and type a query; the page returns every match as a JSON array, in document order.

QueryReturns
$.store.book[0].titleThe title of the first book.
$.store.book[*].titleEvery book title, as an array.
$..priceEvery price anywhere in the document.
$.store.book[0:2]The first two books.
$.store.book[-1]The last book.
$['store']['bicycle']Bracket form, for keys with spaces or dots in the name.

Two limits, stated plainly. Filters such as [?(@.price > 10)] are not supported; filter the result in your own code instead. A query with no matches returns an empty array, not an error, so check the count in the status line before concluding a key is missing.

Worked example

A short API response, as it usually arrives: one line, no spaces.

{"store":{"book":[{"category":"reference","author":"Nigel Rees","title":"Sayings of the Century","price":8.95},{"category":"fiction","author":"Evelyn Waugh","title":"Sword of Honour","price":12.99}],"bicycle":{"color":"red","price":19.95}},"expensive":10}

After formatting with 2 spaces:

{
  "store": {
    "book": [
      {
        "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      {
        "category": "fiction",
        "author": "Evelyn Waugh",
        "title": "Sword of Honour",
        "price": 12.99
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  },
  "expensive": 10
}

The same document answers three questions without scrolling. $.store.book[*].title returns both titles. $..price returns 8.95, 12.99 and 19.95. $.expensive returns 10. Load the API sample above the page to try all three.

Format JSON in code

Use a maintained tool in production. The three below are the usual choices: a command-line filter, a Python one-liner, and a Node snippet.

jq, from the command line

cat response.json | jq .

Add -S to sort keys, -c to minify. jq also answers JSONPath-style questions with its own query language, which is richer than the subset on this page.

Python, standard library only

python3 -m json.tool response.json

Reads a file and prints it formatted. It parses with the same rules as this page, so a file it rejects will fail here too, usually with the same first error.

Node, from a script

const data = JSON.parse(text);
console.log(JSON.stringify(data, null, 2));

Note the trade-off: JSON.parse rounds integers past 2 to the power of 53 and drops the earlier value of a duplicate key without a word. That is exactly what the warnings on this page exist to catch.

Frequently asked questions

Is my JSON uploaded anywhere?

No. The parser runs in your browser. Nothing is uploaded, nothing is logged, and the page works offline once loaded. Even so, remove API keys and personal data before pasting into any online tool.

What does the formatter do with my numbers?

It prints every number exactly as you wrote it, including 1.10 and integers with more than 15 digits. Most browser formatters parse with JSON.parse and silently round large integers, because JavaScript numbers are 64-bit floats. This page keeps the original spelling and warns you when a number is too large to keep every digit.

Does it catch duplicate keys?

Yes, with the line and column of the second one. Duplicate keys are valid JSON grammar, but most parsers keep only the last value and stay quiet, so a duplicate is usually a copy-paste mistake.

Can it fix broken JSON?

The Repair button fixes five common mistakes: trailing commas, single-quoted strings, unquoted keys, comments, and non-JSON constants such as True, None, NaN and Infinity. It lists every change it made. If the text still does not parse, it shows the first remaining error instead of guessing.

How do I pull one value out of a large document?

Switch the output to JSONPath and type a query such as $.store.book[0].title or $..price. The page supports dot keys, bracket keys, indexes, wildcards, recursive descent with .., and slices such as [0:2]. Filters such as [?(@.price > 10)] are not supported.

Can I convert JSON to CSV or YAML?

Yes. Switch the output to YAML or CSV. CSV needs an array of objects at the top level, or a single object that wraps one array, such as {"results": [...]}. Nested objects become dot-notation columns, so {"user": {"name": "Ana"}} becomes a column called user.name.

Sources

Internet Engineering Task Force, RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format: the standard this page checks against, including the grammar, the number rules, and the duplicate-key note.

MDN Web Docs, JSON: how JavaScript parses and prints JSON, and why large integers lose digits.

JSON.org, Introducing JSON: the format in one page, with the grammar diagrams behind the error messages above.

jq, jq Manual: the command-line JSON processor used in the code snippet above.

Agents

Machine readable summary for AI assistants: