JSON Formatter & Validator

Pretty-print, minify and validate JSON with syntax highlighting. Free, fast, and your files never leave your device.

Input

Output


        

What the three buttons actually do

Format parses your text, then writes it back out indented with either two or four spaces, whichever the selector is set to, and colour-codes keys, strings, numbers, booleans and null in the output pane.

Minify parses the same text and writes it back with no whitespace at all, which is what you want for a payload you are about to send or store.

Validate parses and stops there. Nothing is written to the output pane. Use it when you only want a yes or no on whether the document is well-formed.

Sort keys is a modifier rather than a button. Tick it and object keys are reordered alphabetically at every level of nesting before the result is written. It applies to minifying as well as formatting. Array order is never touched, because order is meaningful in an array.

Sorting is genuinely useful for comparison work. Two config files that differ only in key order look completely different in a diff. Sort both, minify both, and the real differences are the only things left.

Reading the error message

When parsing fails, the browser reports the character offset where it gave up. This page converts that offset into a line and column number and appends it to the message, so you get something like "Expected double-quoted property name (line 3, column 3)" rather than an unhelpful raw position.

Here is the part that trips people up. The position marks where the parser noticed a problem, not where you made the mistake. Take this input:

{
  "name": "Ada"
  "age": 30
}

The comma after "Ada" is missing, but nothing is wrong until the parser reaches the quote that starts "age" and finds a new key where it expected a comma or a closing brace. So the error points at line 3, while the character you need to type belongs at the end of line 2. As a rule, when an error lands at the very start of a line, look at the end of the line above it.

If the message has no position information in it at all, which happens with some browsers and some error types, the message is shown on its own without line and column.

Things that look like JSON but will be rejected

JSON is a stricter format than most people remember. These are the failures that come up again and again:

  • A trailing comma after the last element of an array or the last pair in an object. Valid in JavaScript, valid in Python, not valid in JSON. This is the most common single cause of a rejected document.
  • Single quotes. Strings and keys must use double quotes. {'a': 1} fails immediately.
  • Unquoted keys. {a: 1} is a JavaScript object literal, not JSON.
  • Comments. Neither the double-slash nor the slash-star form is allowed. Strip them before pasting.
  • Python values. True, False and None need to be true, false and null in lower case. A printed Python dictionary is not JSON, and neither is one using single quotes.
  • NaN and Infinity. JSON has no way to express them, so serialisers that emit them produce invalid output.
  • Numbers with a leading plus, a leading decimal point, or a trailing one. +5, .5 and 5. are all rejected. Write 5, 0.5 and 5.0.
  • More than one value at the top level. Two objects sitting side by side, or a log file with one object per line, must be wrapped in an array with commas between the items.

What a round trip changes about your data

Formatting is not lossless, because your text is turned into real values and then written back out. Usually that is exactly what you want, but it is worth knowing what shifts:

  • Duplicate keys in the same object collapse. The last one wins and the earlier ones disappear silently.
  • Numbers are re-serialised, so 1.0 comes back as 1 and 1e3 comes back as 1000.
  • Integers larger than about 9 quadrillion lose precision, because every JSON number is handled as a double-precision float. If your document carries large database identifiers, they are safer as strings.
  • Escaped unicode sequences are decoded into the characters they represent.
  • Whitespace inside strings is preserved exactly. Only whitespace between tokens is rewritten.

Practical uses beyond tidying up

Minify before measuring. If you are checking a payload against a size limit, pretty-printed JSON can be well over a third larger than the same data minified, and indentation is not what you are shipping.

Validate before blaming the server. When an API call fails, pasting the exact request body here separates "my JSON was malformed" from "the endpoint rejected valid JSON", which are two very different problems.

Format before reading. A minified response is nearly impossible to scan for a missing field. Two-space indentation is usually the best choice for deeply nested documents because four spaces pushes long structures off the side of the screen.

Related tools

To turn a spreadsheet export into JSON before formatting it, use the CSV to JSON Converter, which also converts back the other way. For XML sources there is the XML to JSON Converter. Once you have two formatted documents, Text Diff shows you line by line what changed between them, and the Fake Data Generator can build sample records when you need a realistic document to test against.

Questions people ask

What does the position in an error message refer to?

It is the character offset where the parser stopped accepting input, counted from the start of the document. This page translates it into a line and column. It marks where the problem was detected, which is often one token after the character you actually need to change.

Can it accept JSON with comments or trailing commas?

No. Parsing uses the browser's strict JSON parser, so relaxed variants are rejected. Remove comments and trailing commas first.

Does sorting keys change my data?

It changes the order keys are written in, recursively, and nothing else. Values are untouched and arrays keep their order. Some systems do treat key order as meaningful, so check before sorting a file you are going to commit.

What indent sizes are available?

Two spaces or four spaces. Tabs are not offered, and neither is a custom width.

Is my JSON sent anywhere when I paste it?

No. Parsing, formatting and validating all happen on your own device using the browser's built-in JSON support, so a config file or an API response containing credentials stays local to your tab.