JSON Formatter & Validator: How to Beautify and Fix JSON Online

Tools 閲覧

Why Format JSON?

JSON transmitted over APIs is usually minified (all whitespace removed) to save bandwidth:

{"name":"Alice","age":30,"city":"London","hobbies":["coding","reading"]}

Formatted ("pretty-printed") JSON is far easier to read and debug:

{
  "name": "Alice",
  "age": 30,
  "city": "London",
  "hobbies": [
    "coding",
    "reading"
  ]
}

How to Format JSON Online

Use the tool.tl JSON Formatter:

  1. Go to tool.tl/json-formatter
  2. Paste your JSON string into the input box
  3. Click "Format" — output appears with syntax highlighting and proper indentation
  4. Click "Minify" to compress it back to a single line
  5. Click "Copy" to use the result

Most Common JSON Syntax Errors

JSON has strict syntax rules. Any single error causes complete parse failure. Here are the most frequent mistakes:

1. Single Quotes Instead of Double Quotes

// ❌ Wrong — JSON requires double quotes
{'name': 'Alice'}

// ✅ Correct
{"name": "Alice"}

2. Trailing Comma

// ❌ Wrong — no comma after the last item
{
  "name": "Alice",
  "age": 30,
}

// ✅ Correct
{
  "name": "Alice",
  "age": 30
}

3. Comments

// ❌ Wrong — JSON does not support comments
{
  // user data
  "name": "Alice"
}

// ✅ Use a conventional field instead
{
  "_comment": "user data",
  "name": "Alice"
}

4. Unescaped Special Characters

// ❌ Wrong — backslashes and quotes inside strings must be escaped
{"path": "C:\Users\Alice"}

// ✅ Correct
{"path": "C:\\Users\\Alice"}

JSON Data Types Quick Reference

TypeExampleNotes
String"hello"Must use double quotes
Number42 / 3.14No quotes
Booleantrue / falseLowercase only
NullnullLowercase only
Array[1, 2, 3]Square brackets
Object{"key": "val"}Keys must be strings

JSON vs Other Data Formats

FormatStrengthsBest For
JSONLightweight, human-readable, browser-nativeAPIs, config files, web data
XMLAttributes, namespaces, mature ecosystemEnterprise systems, SOAP APIs
YAMLComments, less verboseDevOps config (Docker, K8s)
CSVSimple, Excel-compatibleTabular data exports

Frequently Asked Questions

Must JSON keys be strings?

Yes. The JSON spec requires all keys to be double-quoted strings. JavaScript objects allow unquoted keys, but that's not valid JSON — JSON.parse() will reject it.

Does JSON support comments?

Standard JSON does not. If you need comments in a config file, consider JSONC (JSON with Comments, supported by VS Code) or JSON5. Both are supersets of JSON that add comment support.

How do I parse JSON in JavaScript?

Use JSON.parse(jsonString) to convert a JSON string into a JavaScript object. Use JSON.stringify(object, null, 2) to serialize an object to formatted JSON (the 2 sets indentation to 2 spaces).

What does "unexpected token" mean in a JSON error?

It usually means a syntax error at the position indicated — most often a missing comma, an extra comma, a single quote, or an unescaped character. Paste the JSON into the formatter and it will pinpoint the error location.