DEV Community

楊東霖
楊東霖

Posted on • Originally published at devplaybook.cc

The Complete JSON Formatter Guide: Validate, Pretty Print, and Debug JSON Like a Pro

The Complete JSON Formatter Guide: Validate, Pretty Print, and Debug JSON Like a Pro

If you've ever stared at a minified JSON blob and wondered what went wrong, you're not alone. JSON formatting is one of the most common daily tasks for developers — and one of the most tedious when done wrong.

What JSON Formatters Actually Do

A good JSON formatter does four things:

  1. Validates — Catches syntax errors before your API call does
  2. Pretty prints — Converts minified JSON to readable, indented output
  3. Minifies — Compresses JSON for production payloads
  4. Navigates — Lets you collapse/expand nested objects

Why JSON.parse() Errors Happen

The most common JSON parsing errors:

Error Cause Fix
Unexpected token Trailing comma Remove last comma before ] or }
Unexpected end of JSON Unclosed bracket Count opening vs closing brackets
Expected , Missing comma between keys Add commas between all key-value pairs

Keyboard Shortcuts That Save Time

Most web-based JSON formatters support:

Shortcut Action
Ctrl+Enter Format / Validate
Ctrl+Shift+M Minify
Ctrl+S Copy to clipboard
Ctrl+Z Undo

JSON vs JavaScript Object — The Subtle Difference

// ❌ Not valid JSON (trailing comma, single quotes)
{ name: 'Alice', age: 30, }

// ✅ Valid JSON
{ "name": "Alice", "age": 30 }
Enter fullscreen mode Exit fullscreen mode

Rule: JSON requires double quotes around keys and string values. Always.

Real-World Debugging Example

{
  "user": {
    "id": 123,
    "name": "Alice",
    "orders": [
      { "id": 1, "total": 49.99 },
      { "id": 2, "total": 29.99, }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

What's wrong? The trailing comma after "total": 29.99 in the last array item.

How to find it: Use a formatter that highlights lines with errors, or paste and look for red underlines.

When to Use Minified JSON

Use minified JSON when:

  • Sending API responses over the wire (smaller payload = faster)
  • Storing in localStorage (every byte counts)
  • Embedding in <script> tags

Use pretty-printed JSON when:

  • Debugging in development
  • Reading configuration files
  • Reviewing API responses

Conclusion

A solid JSON formatter is in every senior developer's browser bookmark bar. The best ones run entirely client-side (so your data never leaves your machine), support keyboard shortcuts, and give you clear error messages pointing to exactly where the problem is.

Bookmark one. Your future self will thank you.


Level Up Your Dev Workflow

Found this useful? Explore DevPlaybook — cheat sheets, tool comparisons, and hands-on guides for modern developers.

🛒 Get the DevToolkit Starter Kit on Gumroad — 40+ browser-based dev tools, source code + deployment guide included.

Top comments (0)