Toolstia / JSON formatter and validator

Format and validate JSON

Minified API responses, log lines and config files are nearly impossible to read when they arrive as one long string. Paste them here and the tool re-indents them with two spaces, four spaces or tabs, or squeezes formatted JSON back onto a single line for sending. It also tells you whether the text is valid JSON at all.

When something is wrong, the parser message is shown, and where the browser reports a position you also get the line and column. The text is parsed in your browser tab, so API responses and config files with real values do not need to be pasted into an online service. It is equally useful for a quick sanity check on a hand-edited settings file as for reading a large response from a REST endpoint.

How it works

  1. Paste your JSON.
  2. Choose format or minify, the indent size, and whether to sort keys.
  3. Copy the result or download it as a .json file.

Format and minify

Format adds line breaks and indentation so people can read it. Minify removes all optional spaces, which makes the file smaller for sending over a network.

Finding errors

Typical mistakes are a trailing comma, single quotes instead of double quotes, a missing quote around a key, and comments, which JSON does not allow. The message names the problem and where it is.

Sorting keys

Sorting puts every object key in A to Z order, including nested ones. Array order is never changed.

Privacy

Parsing happens in your browser, so API responses and config files are not uploaded.

Example: finding a trailing comma

Paste {"name":"Ana","age":30,} and the tool reports an error at line 1, column 24, pointing just past the final comma. The cause is the trailing comma, which JavaScript and many config formats allow but JSON does not. Delete it and the result turns valid at once.

The wording comes from your browser's own JSON parser, so Chrome, Firefox and Safari describe the same mistake differently, and some messages do not include a position. When there is no line and column, look near the end of what you pasted or just before the character the message names.

What formatting does to your data

The text is parsed into real values and written out again, so the output is always consistent: one space after each colon, strings in double quotes, no stray spaces. Numbers are normalized as well. For example 1.0 is written back as 1 and 1e3 as 1000, which means the same number but not the same characters.

If an object repeats a key, as in {"a":1,"a":2}, standard parsers keep the last value, so the result shows only "a": 2 and the earlier one is silently lost. That is worth knowing if you are debugging data that came from a hand-edited file. Integers beyond about 9 quadrillion also lose digits, because they are read as ordinary floating-point numbers; 12345678901234567890 comes back as 12345678901234567000.

Sort keys: when it helps and what order it uses

Sorting keys is handy before comparing two files in a text diff, because the same data with keys in different order then looks identical. With the box ticked, every object at every level is sorted, while arrays keep their order because the position of an item in a list is usually meaningful.

The order is alphabetical in a way that ignores letter case at first, so keys B, a and C come out as a, B, C and not as the plain code-point order of B, C, a. If you need exact ASCII ordering for a signature or hash, do not rely on this option.

Minify versus format: choosing for the job

Formatted JSON is for people: reviewing a response, editing a settings file, or pasting into documentation. Minified JSON is for machines: it removes every optional space and line break, which saves bytes in a request body, a URL parameter, or a field in a database. For a small object the saving is modest, but for a large array of records it can be a sizeable share of the text.

Tabs, 2 spaces and 4 spaces are all valid, so choose whatever matches the file you are replacing. A project that uses 2 spaces will otherwise get a noisy diff in version control.

What counts as JSON and what does not

This validator follows the standard. Strings and keys need double quotes, so single quotes fail. Comments, trailing commas, undefined, NaN, hexadecimal numbers and unquoted keys are all rejected. A file that is valid JavaScript or valid JSON5 may therefore be reported as invalid here, which is correct if the data will be read by a strict parser.

A document does not need to be an object. A bare value such as a number, a string, true or null is also valid JSON. If you have JSON Lines, where each line is a separate object, paste one line at a time, because the whole text together is not a single valid document.

Questions

Is my JSON sent anywhere?

No. It is processed in your browser tab.

Why does it say invalid when my program accepts it?

Some programs accept relaxed JSON with comments or trailing commas. Standard JSON does not, and this validator follows the standard.

Does formatting change my data?

No, with one caution: very large numbers beyond JavaScript precision can lose digits when the data is re-written.

Is there a size limit?

No fixed limit, but files of tens of megabytes may be slow in the browser.

Can it fix broken JSON for me?

No. It points to where parsing failed so you can correct it yourself, but it does not guess what you meant. Fixing the first error often reveals the next one, so work down from the top.

Why does the error point to a spot after the real mistake?

A parser only knows something is wrong when it reaches a character that cannot be there, which is often just after the actual problem, such as the closing brace after a trailing comma.

Does it keep the original order of keys?

Yes, unless you tick sort keys. One exception comes from JavaScript itself: keys that look like whole numbers, such as 1 or 42, are listed first in ascending order.

Can I paste JSON that is wrapped in quotes with backslashes?

Only if it is meant to be a JSON string. Text such as "{\"a\":1}" is valid but gives you a string, not an object. To work with the inner object, remove the outer quotes and the backslashes first.

What file does the download button create?

A file named toolstia.json containing exactly the text in the result box, as formatted or minified at that moment.