toolqik

113 · JSON

JSON Formatter & Validator

Pretty-print, minify and validate JSON with exact error positions.

Runs in your browser
Indent
Options
Output

  

About this tool

JSON is the format almost every API, config file and log speaks, and it’s strict: one stray comma breaks the whole document. This JSON formatter and validator pretty-prints JSON with syntax highlighting, minifies it, and when something is wrong, tells you the exact line and column, shows the surrounding text, and explains the fix in plain English. It runs in your browser, so API responses, tokens and customer data never leave your machine.

How to use it

  1. Paste JSON, drop a .json file onto the box, or click Open file.
  2. With Format as I type on, the result appears instantly. Otherwise click Format, or Minify to remove all whitespace.
  3. Choose 2 spaces, 4 spaces or tabs, and optionally Sort keys A→Z.
  4. The status line shows whether the JSON is valid, plus its size, number of keys, nesting depth and how long formatting took. Copy the result or download it as a file.

Built for large JSON files

Parsing and formatting run in a background worker, so the page stays responsive even with big files. In our tests, formatting took about half a second for an 8 MB file and about 2 seconds for 40 MB (times depend on the data and your device). Text over 1 MB is kept out of the editor box, which browsers struggle with, and the result shows a preview of the first 400 KB. Copy and Download always include the complete output.

Common JSON errors and how to fix them

Click Try it to load each broken example and see how the validator reports it.

ErrorFix
Trailing comma Remove the comma after the last item in an object or array.
Single quotes Use double quotes for every key and string.
Unquoted key Wrap every key in double quotes. JavaScript allows bare keys; JSON doesn’t.
Comment Remove comments, or use JSONC/JSON5 if the tool reading it supports them.
Missing comma Separate every pair of values or properties with a comma.
NaN, Infinity or undefined Use null, or a real number. These JavaScript values don’t exist in JSON.
Python True / None Use lowercase true, false and null. Print with json.dumps(), not str().
Line break inside a string Escape line breaks and tabs inside strings as \n and \t.
Unclosed bracket Every [ needs a matching ] and every { a matching }.

JSON syntax rules in brief

  • Six value types: string, number, boolean (true/false), null, object {} and array [].
  • Keys and strings use double quotes. Inside strings, escape " as \", backslash as \\, and line breaks as \n.
  • No trailing commas, no comments, and no undefined, NaN, Infinity, dates or functions.
  • Numbers have no leading zeros (07 is invalid), no leading +, and no hex.
  • Files should be UTF-8.

JSON vs. JSONC, JSON5 and JavaScript objects

Some files look like JSON but follow looser rules. JSONC (JSON with comments) is used by VS Code settings and tsconfig.json, and allows comments and often trailing commas. JSON5 also allows single quotes, unquoted keys and hex numbers. A JavaScript object literal allows all of that and more. They’re handy for config files people edit by hand, but APIs and JSON.parse accept only strict JSON, which is what this validator checks.

Large numbers lose precision

JavaScript, and therefore every browser-based JSON tool, stores numbers as 64-bit floats, which are exact only up to 9007199254740991 (253 − 1). A larger integer such as a 64-bit database ID or a tweet ID is silently rounded: 12345678901234567890 becomes 12345678901234567000. This formatter warns you when that happens. The real fix is to send large IDs as strings in your API.

Format and validate JSON in code

const pretty = JSON.stringify(data, null, 2);   // 2-space indent
const minified = JSON.stringify(data);          // no whitespace

// Validate: JSON.parse throws a SyntaxError on invalid input
try {
  JSON.parse(text);
} catch (err) {
  console.error('Invalid JSON:', err.message);
}

Why sort keys?

Two JSON documents with the same data can list keys in a different order. Sort keys A→Z puts keys in alphabetical order at every level, so comparing two API responses or config versions shows only real differences. Array order is kept, because in arrays order has meaning.

FAQ

How do I format JSON?

Paste it into the box above and it is formatted instantly with 2-space indentation and syntax highlighting. You can switch to 4 spaces or tabs, sort keys, or minify instead.

Why is my JSON invalid?

The most common causes are trailing commas, single quotes instead of double quotes, unquoted keys, and comments. Strict JSON allows none of these. The validator shows the exact line and column and suggests a fix.

How do I validate JSON?

Paste it into the formatter. If it is valid, the status shows "Valid" with its size and structure; if not, you see the error position, the surrounding text and a plain-English explanation.

Can it handle large JSON files?

Yes. Formatting runs in a background worker, and files of tens of megabytes work. Above about 400 KB of output, syntax highlighting and the on-page preview are limited to keep the page fast, but Copy and Download always include everything.

Why did a large number change after formatting?

Integers above 9007199254740991 (2^53 − 1) can’t be represented exactly in JavaScript, so JSON.parse rounds them. The formatter warns you when this happens. Send such IDs as strings.

Does JSON allow comments?

No. Standard JSON has no comment syntax. Formats like JSONC (used by VS Code and tsconfig.json) and JSON5 add comments, but they are not accepted by JSON.parse or most APIs.

What is the difference between formatting and minifying?

Formatting adds line breaks and indentation so people can read the JSON. Minifying removes all unnecessary whitespace to make it as small as possible for sending over the network.

Does this tool send my JSON anywhere?

No. Parsing and formatting run in your browser.

esc
↑↓ navigate↵ open