JSON formatter

The JSON formatter pretty prints JSON with readable indentation, minifies it to a single line, and validates it, showing exactly where a syntax error is.
Paste JSON and choose Format or Minify.
Indent
Valid JSON. Object, keys: 5. Characters in the result: 161.

Everything runs in your browser; nothing is sent or stored.

  • Paste JSON code and click "Format" or "Minify". For formatting, choose an indent of 2 spaces, 4 spaces, or a tab.
  • Tick "Sort keys" to sort the keys at every level of the structure.
  • When the JSON is valid, the result updates as you type. Below the result, you see the structure type, the number of top-level keys or items, and the number of characters.
  • If the JSON is invalid, clicking "Format" or "Minify" shows the line and column of the error and moves the cursor to it.
  • Click "Copy" to copy the result.

What is JSON?

JSON (JavaScript Object Notation) is a standard text format for representing data, used in APIs, configuration files, and data exchange between applications. An object is written in curly braces {} and holds key-value pairs, and an array is written in square brackets [] and holds a list of values. A value can be a string, a number, true, false, null, an object, or an array.

Formatting and minifying

Formatting adds line breaks and indentation by nesting level, so the structure is easy to read and values are easy to find. Minifying removes the spaces and line breaks outside strings, which reduces the size of the data when you store or send it.

Common syntax errors

The values true, false, and null are written in lowercase only, and a number cannot start with a leading zero or a + sign. Curly quotes (“ ”), which appear when you copy text from a word processor, are not valid: every string is written in straight double quotes ("). A tab or a line break inside a string is not allowed either, so write them as \t and \n.

Common uses

The formatter helps you read an API response, which usually arrives minified on a single line, check a configuration file before you save it, and find a specific value in a nested structure. Before you compare two versions of the same file, format both with sorted keys and the same indentation, then compare the results with the "Diff checker" tool. That way, the comparison shows only changes to values and structure, not differences in key order or whitespace.

JSON in configuration files

Some programs accept JSON extensions in their configuration files, such as comments or a comma after the last item. For example, the Visual Studio Code settings file allows comments. The formatter shows such a file as invalid JSON, even though the program reads it correctly. When you need the data in another format, convert it with the "JSON to CSV converter" and "YAML to JSON converter" tools.

Common errors and the correct syntax

  • {'name': 'site'}Single quotes are not valid. The correct form is {"name": "site"}.
  • {name: "site"}A key without quotes. Every key is written in double quotes.
  • {"ports": [80, 443,]}A comma after the last item in an array is not allowed.
  • {"debug": True}A boolean value that starts with a capital letter. The correct form is true.
  • {"port": 080}A number with a leading zero. The correct form is 80, or "080" as a string.
  • {"a": 1 /* comment */}Comments are not part of the JSON standard.

JSON formatter FAQ

Why is code that works in JavaScript shown as invalid JSON?

JavaScript object syntax is more flexible than the JSON standard: it allows keys without quotes, strings in single quotes, a comma after the last item, and comments. In JSON, keys and strings are written in double quotes only, and neither a comma after the last item nor comments are allowed. The values undefined and NaN, which exist in JavaScript, are not valid in JSON either.

Does the formatter change values or the order of keys?

The structure and values are kept, but some values are written in a standard form: the number 1.0 is written as 1, the number 1e3 is written as 1000, and characters written as Unicode escape sequences are shown as the characters themselves. Keys that are whole numbers, such as "10", always appear at the start of the object. A whole number larger than 9007199254740991 may be rounded, so we recommend storing long IDs as strings.

In what order are the keys sorted?

Keys are sorted by their Unicode character codes. Digits come before uppercase letters, uppercase letters come before lowercase letters, and accented letters and letters from other alphabets come last. The order of items in arrays stays the same.

What happens when the same key appears twice in an object?

A duplicate key is not a syntax error, and the result shows the key once, with its last value. If the result has fewer keys than you expect, check whether the original JSON contains a duplicate key.

Why does the error location point to a different line than the mistake?

The formatter shows where the problem was detected, which is not always where the mistake was made. When a comma is missing at the end of a line, the error is marked on the next line. An unclosed string or bracket is usually marked at the end of the code.

Can I check a large JSON file?

Yes. The formatter accepts up to 2,000,000 characters, and longer input shows a message that it exceeds the maximum length. For a very deeply nested structure, you may see a message that it cannot be processed.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement