JSON Formatter & Validator

Format, validate, and minify JSON with syntax highlighting

JSON Formatter

Tab size:

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:

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.

Frequently Asked Questions

What does the JSON formatter do?
It takes raw or minified JSON and formats it with proper indentation and syntax highlighting for easy reading. It also validates the JSON and shows error messages with line numbers if the syntax is invalid.
Can I minify JSON with this tool?
Yes. The tool has a minify button that removes all whitespace and formatting, producing the smallest possible JSON string. This is useful for reducing payload sizes in APIs and configuration files.
Is my JSON data sent to a server?
No. All formatting, validation, and minification happens locally in your browser using JavaScript JSON.parse and JSON.stringify. Your data never leaves your device.
What causes "Unexpected token" errors?
Common causes include trailing commas after the last item in an array or object (not allowed in JSON), single quotes instead of double quotes, unquoted property names, and missing commas between items. JSON is stricter than JavaScript object syntax.

You might also like