JSON Formatter & Validator

Validate JSON and format it as readable or compact text in your browser.

Enter values and calculate.

Is this JSON valid? Check it, read it, or squeeze it onto one line

Short answer: The JSON Formatter and Validator runs your pasted text through the browser's built-in JSON.parse. If the text is valid, Format JSON prints it with two-space indentation and Minify JSON prints it on a single line without extra whitespace. If it is not valid, you get the parser's error message and an empty Result box. Nothing is repaired.

Key facts

  • The JSON Formatter and Validator accepts exactly one JSON value, which can be an object, array, string, number, true, false or null.
  • The Format JSON button indents every nesting level by two spaces; the tool has no setting for tabs or four spaces.
  • The Minify JSON button outputs the same value on one line with no spaces or line breaks between tokens.
  • When parsing fails, the status line shows "Invalid JSON:" followed by the browser's own error text, and the Result box is cleared.
  • The formatter's script contains no network requests, so the text you paste is not sent anywhere by the tool.
  • The code sets no size limit; the practical ceiling is your browser's memory and speed.
  • The output is rebuilt from the parsed data, so number notation, escape sequences and duplicate keys can differ from what you pasted.

How to use

  1. Paste or type your text into the JSON input box.
  2. Click Format JSON for an indented, readable version, or Minify JSON for a single line. The status line reads "Valid JSON. The output is ready." and the text appears in the Result box.
  3. If the status line shows "Invalid JSON:", fix the text in the input box and click again. Any edit to the input also clears the old result.
  4. Click Copy output to put the Result box content on your clipboard, or Clear to empty both boxes.

Logic

Both buttons share one code path. The text is parsed once, then written back out with a different spacing argument.

parsed = JSON.parse(input)
Format JSON: JSON.stringify(parsed, null, 2)
Minify JSON: JSON.stringify(parsed, null, 0)

No rounding rule is applied by the tool itself. JavaScript reads every JSON number as a 64-bit floating-point value, which is exact for integers up to 9007199254740991 and not beyond.

Worked example

You paste this order from an API response, 170 characters on one line:

{"order":"A-1042","customer":{"name":"Anna","city":"Berlin"},"items":[{"sku":"PEN-01","qty":3,"price":1.50},{"sku":"INK-07","qty":1,"price":12}],"paid":false,"note":null}
StepLinesCharactersWhat changed
As pasted1170Nothing yet
Format JSON21276Two-space indentation; price 1.50 becomes 1.5
Minify JSON1169Only the trailing zero in 1.50 goes away

Each line break is counted as one character. The input was already compact, so minifying saved a single character.

Values that come out different from what you pasted

Valid does not mean identical. The tool parses your text into data and prints new text from that data, so a few things are rewritten.

You pasteYou getReason
1.501.5Numbers are printed in their shortest form
1e31000Exponent notation is expanded
-00Negative zero prints as plain zero
1234567890123456789012345678901234567000The value exceeds 9007199254740991 and loses precision
"\u00e9""é"Escape sequences are written as the actual character
{"a":1,"a":2}{"a":2}With duplicate keys, the last one wins silently

Keep long IDs as strings

Say a database hands you the 64-bit ID 9007199254740993. After one trip through this tool it reads 9007199254740992, which is a different record. The same ID written as the string "9007199254740993" survives untouched. If a number is really an identifier and not a quantity, quote it.

Key order surprises

The tool keeps keys in the order you wrote them, with one exception. Keys that look like non-negative whole numbers move to the front in ascending order. The object {"b":1,"2":2,"1":3,"a":4} comes out as keys 1, 2, b, a. Compare structure by key, not by position.

Common reasons valid-looking JSON is rejected

What you pastedWhy the parser stops
{"a":1,}A trailing comma is not allowed.
{'a':1}Strings and keys need double quotes.
{a:1}Keys must be quoted strings.
{"a":undefined}undefined, NaN and Infinity are not JSON values.
{"a":01}Leading zeros are not allowed in numbers.
// note, then the objectJSON has no comments.
A raw tab inside a stringControl characters must be escaped, for example as \t.

Reading the error message

The error text comes from the browser, so its wording and detail depend on the engine. In V8, the engine behind Chrome, Edge and Node.js, a trailing comma in {"a":1,} gives "Expected double-quoted property name in JSON at position 7 (line 1 column 8)". An empty input gives "Unexpected end of JSON input".

Look one token before the reported position as well. A missing comma or an unclosed quote earlier in the text often makes a later character the one the parser complains about.

What this tool does not do

  • It does not repair broken JSON; trailing commas, single quotes, comments and unquoted keys all produce an error.
  • It does not check a JSON Schema or any business rule such as required fields, types or value ranges.
  • It does not read several JSON values at once, so JSON Lines files with one object per line fail as invalid.
  • It does not offer other indentation, key sorting, syntax highlighting or file upload; input is the text box only.

Frequently asked questions

How do I validate JSON online?

Paste the text into the JSON input box and click Format JSON or Minify JSON. The status line reads “Valid JSON. The output is ready.” when the text parses, and “Invalid JSON:” followed by the parser's message when it does not.

How many spaces does the JSON formatter use for indentation?

It uses two spaces per nesting level. The tool has no option for tabs or four spaces.

Can this tool fix trailing commas or single quotes?

No, it only reports the first syntax error the parser finds. Correct the text in the input box yourself and click the button again.

Is my JSON uploaded to a server?

No, the formatter's script parses the text in your browser and makes no network requests. Follow your organization's rules for confidential data anyway.

Is there a size limit for the JSON I can paste?

The tool sets no limit; the practical limit is your browser's memory and speed. A very large document can make the tab slow or unresponsive.

Why did a big number change after formatting?

JavaScript reads JSON numbers as 64-bit floating-point values, so integers above 9007199254740991 lose precision. For example, 12345678901234567890 comes out as 12345678901234567000. Store such IDs as strings.

Does minifying change my data?

It keeps the values but rewrites the text. Whitespace is removed, 1.50 becomes 1.5, escape sequences such as \u00e9 become the character itself, and a repeated key keeps only its last value.

Why is my JSON invalid when my code accepts it?

The tool uses strict JSON syntax. JavaScript object literals, JSON5 and many config formats allow comments, single quotes, unquoted keys or trailing commas, which a strict parser rejects.

Related tools

Last reviewed: