JSON Formatter

Tidy up messy JSON, minify it for sending, or find the line with the mistake. Your data never leaves the browser.

Paste JSON, then press Format. Shortcut: Ctrl or Cmd + Enter.

Indentation
Options

How to use it

  1. Paste JSON into the input box, or press Open file to pick a .json file.
  2. Press Format to indent it, or Minify to remove spaces and line breaks.
  3. If there is an error, you see the line, the column and the cause. Press Jump to error to go straight to it.

The rules of JSON

JSON is defined by RFC 8259 (December 2017). It has only seven kinds of value: object {}, array [], string, number, true, false and null, and those three words must be lowercase. Any value can stand at the top level, so "hello" or 42 on its own is valid JSON.

  • Strings use double quotes. The quotation mark, the backslash and the control characters U+0000 to U+001F (line breaks included) must be escaped, for example as \", \\, \n or \u00e9.
  • Numbers are decimal, with no leading zeros and no plus sign. 0.5 and 1e-3 are valid; .5, 1., 007, 0x1F, NaN and Infinity are not.
  • Whitespace means space, tab, line feed and carriage return only, around { } [ ] : ,.
  • Names within an object should be unique. If they repeat, the RFC says the behavior of the receiving software is unpredictable. A browser's JSON.parse keeps the last value; this tool keeps both when formatting.

JSON exchanged between systems that are not part of a closed ecosystem must be UTF-8, and a byte order mark must not be added. This tool removes a BOM if it finds one.

The most common mistakes

  • Trailing comma: [1, 2,] → [1, 2]
  • Single quotes: {'a': 'b'} → {"a": "b"}
  • Unquoted name: {a: 1} → {"a": 1}
  • Python values: True, None → true, null
  • JavaScript value: undefined → null
  • Windows path: "C:\data" → "C:\\data"
  • Comment: // note → removed

The tool runs its own character-by-character check, so it can name the cause instead of only a position. For {"a": 1 "b": 2} it reports Line 1, column 9: A comma is missing between two values. A Python True gets Write true in lowercase.

JSON is not a JavaScript object

JSON looks like a JavaScript object literal but is much stricter. JavaScript accepts unquoted names, single quotes, trailing commas, comments, undefined, functions and hexadecimal numbers; JSON accepts none of them. The other way round, since ES2019 every valid JSON text is also a valid JavaScript expression, after the language started allowing the characters U+2028 and U+2029 inside string literals.

Large numbers and key order

Format and Minify change only whitespace. In {"id":12345678901234567890,"price":25000.50}, both numbers stay exactly as written. A round trip through JSON.parse would turn the ID into 12345678901234567000 and the price into 25000.5, because JavaScript numbers are exact only up to 253 − 1. Sorting keys uses character code order: capitals come before lowercase letters, and é comes after z.

Questions

Is my JSON sent to a server?
No. Everything runs in your browser, so you can use it with config files, API responses or data that contains tokens.
Do large numbers and special characters change?
No. The tool only rearranges whitespace and leaves the content alone, so long numbers such as 19-digit IDs and escapes such as \u00e9 stay exactly as written. A formatter that goes through JSON.parse turns 12345678901234567890 into 12345678901234567000.
What are the most common mistakes?
A comma after the last item of a list or object, single quotes instead of double quotes, property names without quotes, comments, and values such as undefined or True. None of these are allowed in standard JSON.
How do I write a Windows path or a line break inside a string?
Double every backslash: "C:\\data". Write a line break as \n instead of pressing Enter inside the quotes. Otherwise the tool reports an invalid escape or a line break inside a string.
Can I validate JSON with comments, such as tsconfig.json?
You can open it, but it will be marked as invalid, because standard JSON under RFC 8259 has no comments. Files like tsconfig.json are read by parsers that accept comments. Remove the comments first if you need valid JSON.
How large a file can it handle?
Files up to 50 MB can be opened, and files of a few MB are usually done without a noticeable wait. Above one million characters, the automatic check while you type is turned off; press Format or Validate to check the text.