DEV Community

楊東霖
楊東霖

Posted on • Originally published at devplaybook.cc

JSON Formatter Online: Format, Validate, and Debug JSON Instantly

JSON Formatter Online: Format, Validate, and Debug JSON Instantly

Unformatted JSON is one of the most frustrating things to debug. A single missing comma or mismatched brace can break everything — and without proper formatting, it's nearly impossible to spot.

A good online JSON formatter does three things: format, validate, and visualize.


What Is a JSON Formatter?

A JSON formatter (also called a JSON beautifier or pretty printer) takes compact or unreadable JSON and restructures it with consistent indentation and line breaks.

Before formatting:

{"user":{"id":1,"name":"Alice","roles":["admin","editor"],"settings":{"theme":"dark","notifications":true}}}
Enter fullscreen mode Exit fullscreen mode

After formatting:

{
  "user": {
    "id": 1,
    "name": "Alice",
    "roles": [
      "admin",
      "editor"
    ],
    "settings": {
      "theme": "dark",
      "notifications": true
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

The same data — but now you can actually read it.


Format JSON Online Free

DevPlaybook JSON Formatter — paste your JSON, get formatted output instantly. No account, no server upload.

Features:

  • Pretty print with 2 or 4 space indentation
  • Minify/compact mode for production
  • Syntax highlighting
  • Collapsible tree view
  • Error detection with line numbers
  • Copy to clipboard in one click

How to Format JSON

In the Browser (Online Tool)

  1. Paste your JSON into devplaybook.cc/json-formatter
  2. Click "Format" (or it formats automatically)
  3. Copy the formatted output

In JavaScript

// Pretty print with 2-space indent
const formatted = JSON.stringify(data, null, 2);

// Minify
const minified = JSON.stringify(data);

// Parse and re-format (normalize)
const normalized = JSON.stringify(JSON.parse(jsonString), null, 2);
Enter fullscreen mode Exit fullscreen mode

In Python

import json

# Pretty print
formatted = json.dumps(data, indent=2)

# From string
normalized = json.dumps(json.loads(json_string), indent=2)

# From file
with open('data.json') as f:
    data = json.load(f)
print(json.dumps(data, indent=2))
Enter fullscreen mode Exit fullscreen mode

In the Terminal

# Using jq (install: brew install jq)
echo '{"a":1,"b":2}' | jq .

# Using Python (no install needed)
echo '{"a":1,"b":2}' | python3 -m json.tool

# Format a file
cat data.json | jq . > data-formatted.json
Enter fullscreen mode Exit fullscreen mode

JSON Validation

Formatting is only useful if the JSON is valid. A JSON validator checks that your JSON follows the spec:

What Makes JSON Invalid?

  1. Trailing commas — not allowed in JSON (unlike JavaScript objects)
   // Invalid
   {"name": "Alice",}

   // Valid
   {"name": "Alice"}
Enter fullscreen mode Exit fullscreen mode
  1. Single quotes — JSON requires double quotes
   // Invalid
   {'name': 'Alice'}

   // Valid
   {"name": "Alice"}
Enter fullscreen mode Exit fullscreen mode
  1. Comments — JSON doesn't support comments
   // Invalid
   {
     // This is a comment
     "name": "Alice"
   }
Enter fullscreen mode Exit fullscreen mode
  1. Unquoted keys — all keys must be strings in double quotes
   // Invalid
   {name: "Alice"}

   // Valid
   {"name": "Alice"}
Enter fullscreen mode Exit fullscreen mode
  1. Undefined / NaN / Infinity — these JavaScript values don't exist in JSON
   // Invalid
   {"value": undefined}
   {"value": NaN}
   {"value": Infinity}
Enter fullscreen mode Exit fullscreen mode
  1. Mismatched brackets — every { needs a }, every [ needs a ]

Reading JSON Error Messages

JSON.parse: unexpected character at line 3 column 12
Enter fullscreen mode Exit fullscreen mode

Go to line 3, count to column 12. The error is usually one character before the reported position (the parser finds the problem after it's already read past the culprit).


JSON Schema Validation

JSON Schema lets you define the structure your JSON must follow — field names, types, required fields, value constraints.

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "type": "object",
  "required": ["id", "name"],
  "properties": {
    "id": { "type": "integer" },
    "name": { "type": "string", "minLength": 1 },
    "email": { "type": "string", "format": "email" },
    "age": { "type": "integer", "minimum": 0, "maximum": 150 }
  }
}
Enter fullscreen mode Exit fullscreen mode

Use JSON Schema to:

  • Validate API request/response bodies
  • Document your data structures
  • Catch data quality issues early

JSON Minification

Minified JSON removes all whitespace to reduce file size. For large datasets or API responses, this reduces bandwidth.

Example:

// 147 characters formatted
{
  "user": {
    "id": 1,
    "name": "Alice"
  }
}

// 34 characters minified
{"user":{"id":1,"name":"Alice"}}
Enter fullscreen mode Exit fullscreen mode

Use minification for:

  • Production API responses
  • localStorage / sessionStorage
  • Data files in web applications

Working with Large JSON Files

Online formatters sometimes struggle with very large JSON files. For files over 10MB:

# jq handles large files efficiently
jq . large-file.json > large-file-formatted.json

# Python (slower but always available)
python3 -m json.tool large-file.json > large-file-formatted.json

# Node.js (streams, for very large files)
node -e "
const fs = require('fs');
const data = JSON.parse(fs.readFileSync('large.json'));
fs.writeFileSync('large-formatted.json', JSON.stringify(data, null, 2));
"
Enter fullscreen mode Exit fullscreen mode

JSON vs JSONC vs JSON5

JSON — the spec. Strict, no comments, no trailing commas.

JSONC (JSON with Comments) — used in VS Code settings, TypeScript configs. Allows // and /* */ comments.

JSON5 — more relaxed: single quotes, trailing commas, comments, unquoted keys. Used in some config formats.

Most validators only accept strict JSON. If your JSON has comments, it's probably JSONC — remove comments before validating.


Common JSON Tools Compared

Tool Where Best For
DevPlaybook JSON Formatter Browser Quick formatting, no install
jq Terminal Scripting, large files, querying
VS Code Editor Dev workflow, syntax highlighting
Python json.tool Terminal Already installed everywhere

JSON in Modern Development

JSON is the lingua franca of web APIs. You'll format JSON when:

  • Debugging API responses (copy from browser DevTools, paste into formatter)
  • Writing JSON config files
  • Working with data pipelines and ETL jobs
  • Storing configuration in databases

A good formatter is a tool you'll use every week. Bookmark devplaybook.cc/json-formatter and you'll have it when you need it.


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)