JSON Formatter & Validator
Format, validate, and minify JSON with syntax highlighting
JSON Formatter
How it works
This tool parses your JSON input using the browser's built-in JSON.parse() method and reformats it with JSON.stringify(). Invalid JSON is caught and the error message is displayed with line and column information when available. The syntax highlighting is applied client-side using span elements with color classes for keys, strings, numbers, booleans, and null values. Everything runs entirely in your browser — no data is sent to any server.
What Is JSON?
JSON (JavaScript Object Notation) is a lightweight data interchange format that has become the standard for transmitting data between web applications, APIs, and services. Despite its name, JSON is language-independent and is used in virtually every programming language — Python, Java, Go, Ruby, PHP, C#, and many more all have built-in JSON support.
JSON is built on two structures: objects (unordered collections of key-value pairs enclosed in curly braces {}) and arrays (ordered lists of values enclosed in square brackets []). Values can be one of six types: strings (double-quoted), numbers, booleans (true/false), null, objects, or arrays. These simple building blocks can represent complex nested data structures.
You'll encounter JSON in REST API responses, configuration files (package.json, tsconfig.json), NoSQL databases like MongoDB and CouchDB, web storage APIs, and data exports from countless services. Its human-readable format and simple structure make it easy to inspect and debug — especially with a good formatter.
JSON Syntax Rules
JSON's strict syntax is both its strength and its most common source of errors. Unlike JavaScript, JSON has no room for ambiguity. Every key must be a double-quoted string — single quotes and unquoted keys are not valid. Strings must also use double quotes; single-quoted string values will fail validation.
Trailing commas are not allowed. A comma after the last element in an object or array is the single most common JSON syntax error. JavaScript and many other languages allow trailing commas, so developers frequently copy code into JSON and forget to remove them.
Comments are not supported. JSON has no comment syntax — no //, no /* */, no #. If you need comments in configuration files, consider using JSON5 or JSONC (JSON with Comments), which some tools like VS Code support. Numbers cannot have leading zeros (use 0.5 not .5), and undefined, NaN, and Infinity are not valid JSON values. All text must be valid Unicode encoded in UTF-8.
Common JSON Errors and How to Fix Them
When your JSON fails to parse, the error message usually points to a character position — but the actual mistake is often earlier in the document. Here are the most frequent issues:
- Trailing comma:
{"name": "Alex", "age": 30,}— remove the comma after the last value. This is by far the most common mistake when hand-editing JSON. - Single quotes:
{'name': 'Alex'}— replace all single quotes with double quotes. This often happens when copying from JavaScript or Python. - Unquoted keys:
{name: "Alex"}— wrap every key in double quotes. JavaScript allows unquoted keys, JSON does not. - Missing commas: Forgetting a comma between properties or array elements. The parser will report an "unexpected token" at the start of the next value.
- Mismatched brackets: An extra or missing
{,},[, or]. Use a formatter to auto-indent and the mismatch becomes visually obvious. - Invisible characters: Byte order marks (BOM), zero-width spaces, or smart quotes copied from word processors. These are invisible in most editors but break JSON parsing. If your JSON looks correct but won't parse, try pasting it into this formatter — it will show you exactly where the error is.
JSON vs Other Data Formats
JSON vs YAML: YAML is a superset of JSON that supports comments, multiline strings, and a more readable indentation-based syntax. It's popular for configuration files (Docker Compose, Kubernetes, GitHub Actions) but is harder to parse correctly due to its complex specification. JSON is simpler and safer for data interchange.
JSON vs XML: XML was the dominant data format before JSON. It supports schemas, namespaces, and attributes, but is significantly more verbose. A simple data structure that takes 50 bytes in JSON might take 150+ bytes in XML. JSON has largely replaced XML in modern web APIs.
JSON vs CSV: CSV is ideal for flat, tabular data (spreadsheets, database exports) but cannot represent nested structures. JSON handles hierarchical data naturally. Use CSV when your data is a simple table; use JSON when it has nesting or mixed types.
JSON vs TOML: TOML is designed specifically for configuration files with a clear, minimal syntax. It supports comments and is easier to read than JSON for config purposes. However, TOML is not widely used for data interchange — JSON remains the standard for APIs and data transfer.
How This Formatter Works
This tool uses your browser's native JSON.parse() to validate your input and JSON.stringify() with configurable indentation to format it. Syntax highlighting is applied client-side to make the structure easy to scan. Invalid JSON is caught by the parser and the exact error position is highlighted.
Your data never leaves your browser. All parsing, formatting, and minification happens in JavaScript on your device. No network requests are made — you can verify this by opening your browser's Network tab or by using this tool offline. This makes it safe to format sensitive data like API keys, tokens, or configuration files containing credentials.