JSON Formatter & Validator

Format, validate, and explore JSON with syntax highlighting and smart auto-repair.

Data never leaves your browser

Input

Output

Paste or type JSON in the input panel, then click Format

How This JSON Formatter Works

This tool parses, validates, and formats JSON data entirely in your browser. Nothing is sent to any server — your data stays private.

Features

  • Format & Beautify: Paste messy JSON and get perfectly indented, syntax-highlighted output. Choose between 2-space, 4-space, or tab indentation.
  • Validate: Instantly check if your JSON is valid. Get clear error messages with the exact line and column where the problem occurs.
  • Smart Auto-Repair: Paste "dirty" JSON — with trailing commas, single quotes, JavaScript prefixes, or comments — and the tool auto-fixes it, showing what was repaired.
  • Tree View: Switch to an interactive tree view to explore deeply nested JSON structures. Expand and collapse nodes to navigate complex data.
  • Minify: Remove all unnecessary whitespace to get the most compact representation of your JSON data.

Frequently Asked Questions

How do I format JSON online?

Paste your JSON into the input field above and click Format. The tool will instantly beautify your JSON with proper indentation and syntax highlighting. You can choose between 2-space, 4-space, or tab indentation using the dropdown.

Why is my JSON invalid?

Common JSON errors include: trailing commas after the last property ({"a": 1,}), single quotes instead of double quotes ({'key': 'value'}), unquoted keys ({key: "value"}), and JavaScript comments (// comment). Our tool auto-detects and repairs these issues.

Is my JSON data safe?

Yes — your data never leaves your browser. All formatting, validation, and auto-repair happens 100% client-side using JavaScript. No data is sent to any server. You can verify this by disconnecting from the internet and using the tool — it works completely offline.

What is the difference between JSON.parse() and JSON validation?

JSON.parse() is the JavaScript built-in function that converts a JSON string into a JavaScript object. If the string contains invalid JSON, it throws a SyntaxError. This tool uses JSON.parse() under the hood but adds user-friendly error messages, line/column pinpointing, and auto-repair for common issues that JSON.parse() alone cannot handle.

What is the difference between JSON and a JavaScript object?

JSON is a strict text format: all keys must be double-quoted strings, values cannot include undefined or functions, and trailing commas are not allowed. JavaScript objects are more permissive — they allow unquoted keys, single quotes, and trailing commas. This tool can auto-repair JavaScript-style objects into valid JSON.

Can I minify JSON to reduce file size?

Yes — click the Minify button to strip all whitespace and produce the most compact representation. This is useful for reducing payload size in API responses and configuration files stored in databases.

How do I fix "Unexpected token" errors in JSON?

"Unexpected token" errors mean there is a syntax issue at a specific position — typically a missing comma, extra comma, missing colon, or unquoted string. Paste your JSON here and the tool will pinpoint the exact line and column of the error, and auto-repair common issues like trailing commas, single quotes, and JavaScript comments.

JSON Examples & Common Patterns

Explore these ready-to-use JSON examples. Click any example to load it into the formatter above.

REST API Response

A typical paginated API response with nested user objects, metadata, and mixed data types — the kind of payload you'd get from a REST endpoint.

{"status":"ok","data":{"users":[{"id":1,"name":"Alice Johnson","email":"alice@example.com","roles":["admin","editor"],"active":true},{"id":2,"name":"Bob Smith","email":"bob@example.com","roles":["viewer"],"active":false}],"pagination":{"page":1,"per_page":20,"total":2}}}

Check it: Formats into a readable structure with nested objects and arrays clearly indented. Try switching to Tree View to explore the hierarchy.

package.json

A realistic Node.js package.json with dependencies, scripts, and configuration — a file every JavaScript developer works with daily.

{"name":"my-app","version":"2.1.0","description":"A production web application","main":"index.js","scripts":{"dev":"vite","build":"vite build","test":"vitest","lint":"eslint ."},"dependencies":{"fastify":"^5.1.0","vite":"^6.2.0"},"devDependencies":{"vitest":"^3.0.0","eslint":"^9.0.0"},"license":"MIT"}

Check it: See how scripts, dependencies, and metadata are clearly separated when properly formatted.

Deeply Nested Configuration

A complex configuration object with 4+ levels of nesting — perfect for testing the tree view with deeply nested structures.

{"app":{"server":{"host":"0.0.0.0","port":3000,"ssl":{"enabled":true,"cert":"/etc/ssl/cert.pem","key":"/etc/ssl/key.pem"}},"database":{"primary":{"host":"db.example.com","port":5432,"name":"myapp","pool":{"min":2,"max":10}},"replica":{"host":"db-replica.example.com","port":5432}}},"logging":{"level":"info","outputs":["stdout",{"type":"file","path":"/var/log/app.log"}]}}

Check it: Use Tree View to expand and collapse individual sections like server.ssl and database.primary.pool.

Dirty JSON — Auto-Repair Demo

This example contains trailing commas, single quotes, comments, and a JavaScript prefix. Our auto-repair pipeline fixes all of these automatically.

var apiData = {
  // User configuration
  'name': 'Test User',
  'settings': {
    'theme': 'dark',
    'notifications': true,
    'tags': ['important', 'starred',],
  },
}
  • JS prefix: var apiData = is stripped
  • Comments: // User configuration is removed
  • Single quotes: Converted to double quotes
  • Trailing commas: Removed after 'starred' and the settings object

Invalid JSON — Error Detection ✕

This JSON is broken beyond auto-repair — a missing closing bracket and a missing colon. Load it to see our error messages pinpoint the exact location.

{
  "users": [
    {"name": "Alice", "age": 30},
    {"name": "Bob", "age" 25}
  "total": 2
}
  • Missing colon: "age" 25 should be "age": 25
  • Missing bracket: The users array is never closed with ]

Common JSON Errors & How to Fix Them

Getting a JSON syntax error? Here are the most common mistakes and how to fix them. Our tool auto-repairs many of these — just paste your JSON and click Format.

Error Example Fix
Trailing comma {"a": 1, "b": 2,} Remove the comma after the last property. ✅ Auto-repaired
Single quotes {'key': 'value'} JSON requires double quotes. Replace ' with ". ✅ Auto-repaired
Unquoted keys {name: "Alice"} Wrap keys in double quotes: {"name": "Alice"}. ✅ Auto-repaired
Comments {"a": 1} // note JSON does not allow comments. Remove // and /* */ blocks. ✅ Auto-repaired
Missing comma {"a": 1 "b": 2} Add a comma between properties: {"a": 1, "b": 2}
Missing colon {"age" 25} Add a colon after the key: {"age": 25}
Unclosed bracket {"items": [1, 2, 3} Close the array with ]: {"items": [1, 2, 3]}
Unclosed string {"name": "Alice} Close the string with a matching double quote
JavaScript prefix var data = {...} Remove the variable declaration. ✅ Auto-repaired
Unexpected text Response: {...} Remove any text before or after the JSON. ✅ Auto-repaired

Items marked ✅ are automatically fixed by our smart auto-repair feature. Paste your broken JSON above and the tool will fix what it can and highlight what it can't.