TestingAPIs is still being built. If something breaks, email support@testingapis.com.

JSON formatter and validator

Runs in your browser; nothing is uploaded

Format, validate and minify JSON. Errors point to the exact line and column.

Input

Formatted JSON appears here as you type.

Ready
Ln 1, Col 1

What the formatter does

JSON is the format most web APIs use for request and response bodies. Servers usually send it minified, with every space and line break removed, which is compact but hard to read. Formatting (pretty-printing) adds indentation so you can see which keys belong to which object; minifying removes it again.

To format JSON the tool has to parse it, so formatting also validates. If the text isn't valid JSON you get the line and column where parsing stopped, what was expected there, and the usual cause. Comments, trailing commas, single quotes, bare keys and Python's True/None can be fixed for you: the tool lists every change first and applies nothing until you confirm.

Formatting here never changes a value. The tool uses its own parser rather than JSON.parse, so numbers keep the digits they were written with (12345678901234567890 and 1.50 stay as they are), escapes such as \u00e9 stay escapes, and duplicate keys stay where they were. When a document holds data that JSON.parse would change, such as integers beyond 2^53 or a key that appears twice, the Inspector lists it under Data warnings.

How to use this tool

  1. 1Paste JSON into the Input pane, drop a .json file on it, or press Ctrl+O to open one (up to 5 MB). Examples has samples to try.
  2. 2The Output tab shows the result as you type. Choose the indent (2 spaces, 4 spaces or tabs), sort keys, or switch between Pretty and Minified. The arrows in the gutter fold objects and arrays.
  3. 3To rewrite the input itself, use Format (Shift+Alt+F) or Minify (Shift+Alt+M). Ctrl+Z undoes either, as well as Clear and applied fixes.
  4. 4If the JSON is invalid, the status bar and the Output tab show where. Press F8 to put the cursor on the error, or Review fixes to see the automatic repairs.
  5. 5Tree, Table, JSONPath and Compare show the same data in other ways: select a tree node to copy its path or value, query with an expression such as $.items[?(@.price < 10)].id, or paste a second document to list what changed.
  6. 6Copy the output, or download it formatted or minified (Ctrl+S). Press ? to see every keyboard shortcut.

Troubleshooting

Trailing comma: remove the , before }
JSON doesn't allow a comma after the last item of an object or array. Delete it, or use Review fixes. It usually comes from JavaScript code or a config file written by hand.
Property names must be in double quotes
The text is a JavaScript object literal ({name: 'x'}), not JSON. Every key and string needs double quotes. Review fixes adds them.
True is Python; JSON uses true
The data was printed with Python's print() or str(). Use json.dumps() to produce JSON, or let Review fixes replace True, False and None.
Unexpected end of input: the object opened on line 1 is not closed
The text stops before every { and [ is closed. A copied response was probably cut off; copy it again, or save it to a file and open that.
Unexpected content after the JSON value
There are two or more JSON values one after another. Wrap them in an array, or, for newline-delimited JSON (NDJSON) logs, check one line at a time.
The text starts with a byte order mark (BOM)
The file was saved as 'UTF-8 with BOM'. Many parsers reject the invisible mark at the start. Save it as plain UTF-8, or use Review fixes to remove it.
Strings can't span lines
A string contains a raw line break, often from pasting text with newlines. Replace the break with \n.
A number in your code differs from the one in the JSON
Integers above 9,007,199,254,740,991 lose precision when JavaScript parses them, so a 19-digit ID can change. This tool shows the digits as written and warns about them; in your API, send such IDs as strings.

Frequently asked questions

Is my JSON uploaded anywhere?

No. Parsing, formatting and every view run in your browser tab. To survive a reload, what you paste is kept in this tab's session storage until you clear it or close the tab. Copy link puts the input in the link after #, which browsers never send to a server, but anyone you give the link to can read it. Your settings, such as the indent, are saved in this browser.

Does formatting change my data?

No. Values are copied exactly as written, including big numbers, escapes and duplicate keys. Two options do change the text on purpose: Sort keys reorders keys (by character code, so uppercase sorts before lowercase), and Minify removes whitespace outside strings.

What happens to duplicate keys?

They are kept and shown as written, with a warning. The JSON standard leaves duplicate keys undefined; JSON.parse and most libraries keep only the last value, so code reading this document will probably see just one of them. The Table, Compare and JSONPath views follow the same last-one-wins rule.

Which JSONPath syntax is supported?

The common Goessner syntax: $ for the root, .key and ['key'], indexes including negative ones, [*] and .. for recursive descent, unions such as [0,2], slices such as [1:3], and filters such as [?(@.price < 10 && @.inStock)]. Filters compare numbers as JavaScript numbers, so integers beyond 2^53 compare approximately.

How large a file can it handle?

Files up to 5 MB open directly. A document of about 4 MB takes a fraction of a second to check and format on a typical laptop; above about 200 KB the tool waits for a pause in typing before checking again. Nesting deeper than 2,000 levels is reported as an error.