UltKit

JSON Formatter & Validator

Paste JSON to pretty-print it, minify it or sort its keys. If it does not parse, the formatter shows the line and column where the parser gave up, with a pointer under the problem, so a missing comma in a 3,000-line response takes seconds to find.

Output

0 characters · 0 words · 0 lines

0 characters · 0 words · 0 lines

Runs entirely in this browser tab. Your text is never uploaded or stored.

JSON value types

RFC 8259 allows exactly these values. Objects and arrays nest; everything else is a leaf.

TypeExampleRule
Object{"id": 7, "tags": ["a"]}Keys must be double-quoted strings; members are separated by commas with no trailing comma.
Array[1, "two", null]Ordered list of any values, mixed types allowed.
String"caf\u00e9 \"quoted\""Double quotes only; control characters must be escaped; \u escapes use four hex digits.
Number-12.5e3Decimal only: optional minus, no leading zeros, optional fraction and exponent. No NaN or Infinity.
true, false, nulltrueLower case, unquoted.

What the parser rejects

Each input below was passed to the same JSON.parse the formatter uses when this page was built.

InputProblemJSON.parse
{"a": 1,}Trailing commaRejected
{'a': 1}Single-quoted stringsRejected
{"a": 1 /* note */}CommentsRejected
{a: 1}Unquoted keyRejected
{"n": NaN}NaN is not a JSON numberRejected
{"n": 012}Leading zeroRejected
{"n": 0x1F}Hexadecimal numberRejected

Escapes in JSON strings

CharacterWritten in JSON
Double quote"\""
Backslash"\\"
Line feed"\n"
Tab"\t"
Carriage return"\r"
Control character U+0001"\u0001"
Forward slash (escape optional)"/"
Non-ASCII letter (no escape needed)"é"

The rules a valid JSON document follows

JSON is specified by RFC 8259 (identical in substance to ECMA-404). A document is a single value: an object, an array, a string, a number, true, false or null. Object keys are always strings in double quotes. Strings use double quotes only and must escape the quote, the backslash and every control character below U+0020; tabs and line breaks inside a string are therefore written as \t and \n. RFC 8259 also requires UTF-8 for JSON exchanged between systems.

Numbers are decimal: no leading zeros, no hexadecimal, no NaN or Infinity, and no plus sign in front. The format has no comments and no trailing commas. Those last two rules cause most real-world errors, because JavaScript object literals, JSON5 and many config files allow both. The reference table below was produced by feeding each common mistake to the same parser the formatter uses.

Pretty-print, minify, sort

Pretty-printing adds line breaks and indentation so the structure is readable; two spaces is the most common style in JavaScript projects, four spaces is the usual choice with Python's json.dumps(indent=4), and tabs let each reader choose a width. Minifying removes every insignificant space, which shrinks API payloads and makes a document fit on one line for logs or environment variables.

Sort keys orders the members of every object alphabetically, recursively. JSON objects are unordered by definition, so sorting does not change meaning, but it makes two documents from different systems far easier to compare. Be aware that parsing turns numbers into JavaScript doubles: integers above 2^53 (9,007,199,254,740,992), such as some database IDs, lose precision when reformatted, so keep those as strings.

From JSON to other formats

A formatted document is easier to read, but sometimes you need it in another shape. An array of objects becomes a spreadsheet with JSON to CSV, and the data converter moves whole files between JSON, XML, YAML and CSV.

Frequently asked questions

Why does the formatter reject my JSON with comments?
Standard JSON has no comment syntax; RFC 8259 leaves it out on purpose. Remove the comments, or keep the file as JSONC or JSON5 if the tool that reads it supports those formats.
What does "Unexpected token" mean in a JSON error?
The parser met a character that cannot appear at that position, such as a single quote, a trailing comma before } or an unquoted key. The line and column shown point at that character.
Does sorting keys change my data?
No. Object member order carries no meaning in JSON, so the sorted document is equivalent. Array order is meaningful and is never changed.
Why did a long number change after formatting?
JavaScript stores numbers as 64-bit floats, which represent integers exactly only up to 2^53. Larger IDs are rounded when parsed; transmit them as strings to keep every digit.
Can I format a JSON file instead of pasting?
Open the file in any text editor, select all and paste it here. Very large files of tens of megabytes may make the tab slow while the textarea renders them.