SiteBox

JSON Formatter & Validator

Clean up your JSON, catch errors, and get back to work

Processed in your browser

JSON
0 charactersExample data

Output

FORMATTED
0 charactersUTF-8
Example loaded · Valid JSON
⌘Enter to format

From messy JSON to readable data

01

Add your JSON

Paste a response or open a file. Try the example to explore the tool

02

Choose your output

Format for readability, minify for compactness, or validate the syntax

03

Take it with you

Copy the result or download a JSON file. No account needed

Example: Finding the Error in a Config File

Here is a small settings file that a deployment rejected with "Unexpected token":

{
  "name": "orders-service",
  'port': 8080,
  "features": ["audit", "retry",],
  "timeoutMs": 3000,
}

Paste it in and click Validate. The validator stops at the first problem and reports its line and column: line 3, where 'port' uses single quotes. Fix that and validate again; the next stop is the trailing comma after "retry", then the trailing comma after 3000. JSON only reports one error at a time because the parser cannot guess what you meant after the first mistake, so expect to repeat validate–fix two or three times on a hand-edited file.

Once it passes, Format gives you:

{
  "name": "orders-service",
  "port": 8080,
  "features": [
    "audit",
    "retry"
  ],
  "timeoutMs": 3000
}

The Rules That Trip People Up

JSON is defined by RFC 8259 and is stricter than the JavaScript object syntax it resembles. These are the differences behind most "invalid JSON" errors:

Allowed in JavaScriptIn JSON
{name: "Ana"} – unquoted keysKeys must be double-quoted strings: {"name": "Ana"}
'single quotes'Only "double quotes"
Trailing commas [1, 2,]Not allowed
// commentsNot allowed at all
undefined, NaN, InfinityNot valid values; use null or a string
Hex numbers 0x1F, leading zeros 007Decimal numbers only, no leading zeros

Two more sources of trouble are invisible: "smart quotes" (“ ”) pasted from a word processor or chat app, and raw line breaks inside a string, which must be written as \n.

Format, Minify, Validate: When to Use Which

  • Format re-indents with 2, 4 or 8 spaces. Use it to read an API response, review a change, or paste a readable payload into a bug report. Two spaces is the common default in JavaScript projects; four is typical in Python codebases.
  • Minify strips every non-essential space and line break. Use it when a value has to fit on one line, for example in an environment variable, a curl command or a test fixture.
  • Validate checks syntax and tells you how many top-level keys or array items were found, which is a quick sanity check that you copied the whole response.

All three run through the browser's native JSON.parse and JSON.stringify, so the result is exactly what a JavaScript application would see. Nothing is uploaded, which is important when the payload contains customer records or access tokens.

Things the Formatter Changes (and Doesn't)

Parsing and re-serialising has a few side effects worth knowing:

  • If a key appears twice in the same object, only the last value is kept.
  • Very large integers above 253 (9,007,199,254,740,991), common in database IDs, lose precision because JavaScript numbers are 64-bit floats. If you see an ID end in unexpected zeros, the source should send it as a string.
  • Number formats are normalised: 1.0 becomes 1 and 1e3 becomes 1000.
  • Key order is preserved as written for ordinary string keys.

Neighbouring Tools

JSON often arrives wrapped in another encoding. A JWT payload or an email attachment is Base64, so decode it with the Base64 tool first. A JSON object passed in a query string is percent-encoded; decode it with the URL Encoder. To pull specific values out of a large text dump, test a pattern with the Regex Tester. See all developer tools.

Frequently Asked Questions

Why does my JSON fail with "Unexpected token"?

The most common causes are single quotes, unquoted keys, trailing commas, comments, or smart quotes pasted from a document. The error message shows the line and column of the first problem.

Can JSON contain comments?

No. Standard JSON has no comment syntax. Remove the comments, or keep them in a separate field such as "_comment".

Why did the formatter change my large ID number?

Integers larger than 9,007,199,254,740,991 cannot be represented exactly in JavaScript, so they are rounded. Store such IDs as strings.

Should I indent with 2 or 4 spaces?

Either is valid JSON. Follow the convention of the project you are working in; 2 spaces is the most common default for JavaScript tools.

Is my JSON sent to a server?

No. Parsing and formatting use your browser's built-in JSON functions, so the data stays on your device.