araç köşesi

JSON Formatter and Validator

Pretty print JSON, minify it, and see exactly where an invalid file breaks

Your data stays with you. Conversion happens inside the browser; nothing is sent to a server.

How it works

Paste JSON into the left pane and the formatted version appears on the right immediately. The output layout sets the indentation: 2 spaces is the default in most languages and editors, 4 spaces makes the levels easier to follow by eye in deeply nested data, and the minified option strips every space and line break down to a single line. Sorting the keys alphabetically is not limited to the top level — it reaches into every nested object, including objects inside arrays — which is what makes two versions of a file comparable when they differ only in the order of their fields. If the text is not valid JSON, no output is produced: instead you are told the line and the column at which the problem became visible. The result line reports how many lines went in and how many came out, so the effect of expanding or minifying is visible at a glance. The output can be copied or downloaded as a .json file, and the text you paste never leaves your browser.

This tool is also known as json formatter, json validator, pretty print json, json beautifier, minify json.

What is JSON?

JSON's grammar is stricter than it looks. Keys must be in double quotes, a comma cannot follow the last element, comments are not allowed, the decimal mark is always a dot, and the only permitted values are objects, arrays, strings, numbers, true, false and null. That strictness is a design choice rather than an oversight: with so few rules, every language reads the same text in the same way. Validity is a matter of grammar alone, though — a document that parses cleanly can still hold entirely wrong data.

What is indentation?

Indentation shifts each level of a nested structure inwards by a fixed number of spaces so that the hierarchy can be seen at a glance. In JSON it has no effect on the data whatsoever: the same content written with two spaces, with four, or with none at all parses into exactly the same values. Indentation exists for the human reading the file, which is why expanding a document while you inspect it and minifying it before pasting it somewhere is not an inconsistency.

What is the difference between formatting and minifying?

Both keep the same data and change only its appearance. Formatting adds line breaks and indentation to make the structure legible, which is what you want for inspecting, debugging and showing a file to someone else. Minifying removes every unnecessary space and puts the text on one line, cutting the character count, which is what you want for a field that accepts a single line. Neither direction loses structure: a minified document expands back to the same values, because whitespace between tokens means nothing to a parser. Only the way numbers are written can shift, since the text is parsed and rewritten rather than shuffled.

How to read the line and column in the error

A JSON parser reports the failure at the first character that breaks a rule, and that is usually not where the mistake was made. A quotation mark that was never closed, for instance, is only detected at the start of the next line, because everything up to that point was still legal string content.

So when the reported line looks innocent, read the line above it. The usual culprits are short and repetitive:

  • A comma after the final element — JSON does not allow it
  • Keys with no quotes, or with single quotes instead of double
  • A leading zero in a number, or a comma used as the decimal mark (it must be a dot)
  • A bracket or brace left unclosed by a partial copy and paste

Which indentation should you choose?

Indent when a person is going to read the JSON — reviewing it, screenshotting it, attaching it to a bug report. Two spaces keep the lines short; four make it obvious which field belongs to which object once the nesting runs deep.

Minify when a machine is the reader: a configuration field, an environment variable, a database column or a form that accepts one line only. The whitespace carries no data there, it just takes up room.

What a round trip does not preserve

Formatting keeps your data but does not hand the file back byte for byte. The text is parsed into real values and written out again, so 1.0 comes back as 1, 1e3 comes back as 1000, and an integer beyond roughly sixteen digits comes back rounded. That is a property of how numbers are held in memory, and it applies to every JSON tool built on a standard parser, not only to this one.

Duplicate keys are the other case worth knowing. JSON permits the same name to appear twice in one object, and parsers keep the last occurrence, so the earlier value disappears from the output without a warning. If you are formatting a file where that could matter — a merged configuration, for example — count the keys before you replace the original.

Frequently asked questions

How do I pretty print JSON?

Paste the text into the left pane and pick an indentation; the formatted version appears on the right as you type, ready to copy or to save as a .json file.

How can I tell whether my JSON is valid?

If output appears, the text is valid JSON. If it is not, you get a message in place of the output naming the line and column where the problem shows up.

What is sorting the keys good for?

Comparing two files. Two exports that differ only in field order look completely different in a diff; sort both and only the real differences are left on screen.

Does formatting change my data?

The values stay the same; only whitespace changes, plus key order if you ask for it. The one thing to watch is how numbers are written — any parser rewrites 1.0 as 1 and rounds integers beyond about sixteen digits.

What is minified JSON for?

Whitespace and line breaks mean nothing to a JSON parser, they only take up space. A single-line version is what you want for configuration fields, environment variables and any form that accepts one line.