Skip to main content
DeveloperJuly 9, 20263 min read

How to Format and Validate JSON (and Fix the 7 Most Common Errors)

Unreadable JSON on one line? "Unexpected token" error? Learn how to beautify, validate and minify JSON, and how to fix the syntax errors developers hit most often.

#json#json formatter#json validator#api#developer tools
How to Format and Validate JSON (and Fix the 7 Most Common Errors)

JSON in 30 Seconds

JSON (JavaScript Object Notation) is the most widely used data format on the web: API responses, configuration files (package.json, tsconfig.json), data exports, logs. It's built from just a few elements:

{
  "name": "AwesomeToolkit",
  "tools": 90,
  "free": true,
  "languages": ["en", "fr", "es"],
  "owner": null
}

Objects in braces, arrays in brackets, strings in double quotes, numbers, true, false and null. That's all. And yet a single misplaced comma is enough to break everything.

Format, Validate, Minify: What's the Difference?

OperationWhat it doesWhen to use it
Format (beautify)Adds indentation and line breaksReading an API response, debugging
ValidateChecks the syntax and locates errorsBefore committing a config file, after editing by hand
MinifyRemoves all unnecessary whitespaceProduction, network transfer, embedding in a URL or a variable

Format JSON Online

The JSON formatter does all three, in your browser: you can paste JSON containing tokens, customer data or configurations without it being sent anywhere.

Format JSON

Format and validate your JSON instantly.

Try it for free
  • Paste your JSON: it's formatted and highlighted.
  • Choose the indentation: 2 spaces, 4 spaces or a tab.
  • On error, the tool shows the exact line and column and explains the problem.
  • Very large numbers (beyond 2^53, like some IDs) are kept exactly as written, where many tools silently round them.
  • Duplicate keys — valid in theory, but a classic source of bugs — are flagged.

The 7 Most Common JSON Errors

1. Trailing Comma

{ "a": 1, "b": 2, }

JavaScript accepts it, JSON doesn't. Remove the last comma.

2. Single Quotes

{ 'name': 'Alice' }

JSON only accepts double quotes, for keys as well as strings.

3. Keys Without Quotes

{ name: "Alice" }

Valid in JavaScript, not in JSON: every key must be in double quotes.

4. Comments

{ "port": 8080 // dev port }

Standard JSON doesn't support comments. Some tools accept them (JSONC, used by VS Code), but an API won't.

5. Missing Comma Between Two Elements

Often after copying and pasting a block: the error is reported at the start of the next element, not at the end of the previous one.

6. Unescaped Special Characters

A line break or a double quote inside a string must be escaped: \n, \". Windows paths need doubled backslashes: "C:\\Users\\file.txt".

7. Invalid Values

undefined, NaN, Infinity and dates like new Date() don't exist in JSON. Use null, a number or an ISO string ("2026-07-09T10:00:00Z").

Reading an error message

"Unexpected token" means the parser found a character it didn't expect at that position. Look at the indicated spot — and at the character just before it: that's often where the real problem is (a missing comma, an unclosed quote).

Going Further

Conclusion

A JSON formatter is one of those small tools you use ten times a day without thinking about it. Format to read, validate before committing, minify for production — and when the parser complains, the error is almost always one of the seven above.

Share this article

Ready to use our dev tools ?

Free, fast, and no sign-up required.

Try it now

Related articles