Table of contents
JSON is everywhere. APIs return it, configuration files use it, databases export it. But raw JSON from an API response or a log dump is often a single continuous line of text, virtually unreadable to a human. A free JSON formatter turns that wall of text into clean, indented, readable code in one click.
This guide explains what JSON formatters and validators do, when to use them, and how to fix the most common JSON errors.
What is JSON?
JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging structured data. It uses a simple syntax of key-value pairs, arrays, and nested objects:
{
"name": "Alice",
"age": 30,
"skills": ["JavaScript", "Python"],
"address": {
"city": "London",
"country": "UK"
}
}
Despite its name, JSON is language-independent. Nearly every programming language (Python, Java, Ruby, PHP, Go, Swift) has built-in support for reading and writing JSON. It has become the standard format for web APIs, replacing older formats like XML.
What a JSON formatter does
A JSON formatter (also called a JSON beautifier or JSON pretty-printer) takes compact or poorly formatted JSON and adds:
- Indentation: Each nested level is indented by 2 or 4 spaces (you choose).
- Line breaks: Each key-value pair and array item appears on its own line.
- Consistent spacing: Spaces are added around colons and after commas according to standard conventions.
The result is JSON that is easy to read, easy to navigate, and easy to spot errors in.
Before formatting:
{"user":{"id":1042,"name":"Alice","email":"alice@example.com","roles":["admin","editor"],"active":true}}
After formatting:
{
"user": {
"id": 1042,
"name": "Alice",
"email": "alice@example.com",
"roles": [
"admin",
"editor"
],
"active": true
}
}
Same data. Completely different readability.
What a JSON validator does
A JSON validator checks whether your JSON is syntactically correct according to the JSON specification (RFC 8259). It reports:
- The error type: What kind of syntax mistake was found.
- The location: The line number and character position of the error.
- What was expected: What the parser expected to find at that position.
This is far more useful than an ambiguous "invalid JSON" message from your application or API client.
When to use a JSON formatter and validator
Debugging API responses: When an API call fails or returns unexpected data, paste the raw response into a formatter to see the full structure clearly. Expand and collapse nested objects to find the data you need.
Writing JSON configuration files: Application config files, package.json, tsconfig.json, and similar files are hand-written JSON. A validator catches typos and syntax errors before they cause cryptic startup failures.
Reading API documentation examples: API documentation often shows JSON examples as minified single lines for compactness. Paste them into a formatter to understand the structure before writing code.
Comparing two JSON objects: Formatted JSON is much easier to compare side-by-side than minified JSON.
Sharing JSON in code reviews or tickets: Formatted, indented JSON is far easier for colleagues to read in a GitHub comment or a Jira ticket.
Learning JSON syntax: If you are new to JSON, formatting examples helps you visually understand how nesting and data types work.
The most common JSON errors (and how to fix them)
1. Trailing comma
This is the most frequent JSON error, especially for developers coming from JavaScript:
{
"name": "Alice",
"age": 30, ← trailing comma - not allowed in JSON
}
Remove the comma after the last item in an object or array. JSON does not allow trailing commas. JavaScript does (in modern syntax), but JSON is stricter.
2. Single quotes instead of double quotes
JSON requires double quotes around all strings and all keys. Single quotes are not valid:
{
'name': 'Alice' ← invalid: single quotes
}
Replace every single quote with a double quote:
{
"name": "Alice" ← correct
}
3. Unquoted keys
Unlike JavaScript objects, JSON keys must always be quoted strings:
{
name: "Alice" ← invalid: key without quotes
}
Add double quotes around the key:
{
"name": "Alice" ← correct
}
4. Comments in JSON
JSON does not support comments. A common mistake from developers who use JSON for config files:
{
"port": 3000, // development port ← invalid: comments not allowed
"debug": true
}
Remove all comments. If you need to annotate configuration, use a format that supports comments (like YAML or JSONC) or add a dedicated "_comment" key as a convention.
5. Mismatched brackets
Missing a closing } or ], or using the wrong type of bracket, causes parse failures:
{
"users": [
{"id": 1},
{"id": 2}
← missing closing ]
}
A JSON validator will tell you exactly which line is missing a bracket. Use the formatter to visualize the nesting structure and spot where the brackets go out of balance.
6. Unescaped special characters in strings
Certain characters inside strings must be escaped with a backslash:
\"for a literal double quote\\for a literal backslash\nfor a newline\tfor a tab
{
"message": "He said "hello"" ← invalid: unescaped quotes
}
Correct version:
{
"message": "He said \"hello\""
}
7. Numbers as strings (or vice versa)
Numbers in JSON do not use quotes. If a field should be a number, store it without quotes:
{
"count": "42" ← this is a string, not a number
}
If your application expects a number and receives a string, type coercion errors will follow. Use the correct data type from the start.
JSON formatter vs. code editor JSON plugin
Code editors like VS Code, WebStorm, and Sublime Text have built-in or plugin-based JSON formatting. You can press a keyboard shortcut to format a JSON file and see inline error highlighting.
For quick one-off tasks like pasting an API response to inspect it, validating a config file, or sharing formatted JSON in a ticket, an online formatter like FixTools is faster than opening a code editor.
For regular development work, use your editor's JSON tools. For ad-hoc debugging and sharing, use an online formatter.
Minifying JSON: The reverse operation
Minification is the opposite of formatting: it removes all whitespace to produce the smallest possible JSON string. Minified JSON is used in production API responses, embedded configs, and data files where file size matters and human readability does not.
Use the FixTools JSON Minifier when you need to reduce the size of JSON for deployment. Use the formatter when you need to read or edit it.
JSON compared to other data formats
JSON vs XML: XML is more verbose and harder to read. JSON is lighter and more widely used for modern web APIs. Most new APIs use JSON; XML remains common in enterprise systems and document storage.
JSON vs YAML: YAML is a superset of JSON and is more human-friendly (supports comments, less punctuation). YAML is popular for configuration files (Docker Compose, Kubernetes, CI/CD pipelines). JSON is better for machine-to-machine data exchange because it has fewer edge cases.
JSON vs CSV: CSV is great for tabular data with consistent columns. JSON handles nested structures and mixed data types better. APIs typically return JSON; data exports for spreadsheets often use CSV.
Format and validate your JSON now
Paste your JSON into the FixTools JSON Formatter for instant formatting with 2-space or 4-space indentation. Run it through the JSON Validator to catch syntax errors with exact line numbers. Both tools run entirely in your browser, so your data never leaves your device.
Try it free — right in your browser
No sign-up, no uploads. Your data stays private on your device.
Frequently asked questions
6 questions answered
QWhat is the difference between a JSON formatter and a JSON validator?
A JSON validator checks whether your JSON is syntactically correct. It reports errors like missing commas, unquoted keys, or mismatched brackets. A JSON formatter (also called a JSON beautifier) takes valid JSON and rearranges it with proper indentation and line breaks to make it human-readable. Most tools combine both features.
QIs my data safe when I paste JSON into an online formatter?
FixTools JSON Formatter runs entirely in your browser. Your JSON data is never sent to any server. All formatting and validation happens locally on your device. This makes it safe for sensitive API responses and private configuration files.
QWhy is my JSON showing an error even though it looks correct?
Common hidden issues include: trailing commas after the last item in an array or object (valid in JavaScript but not in JSON), single quotes instead of double quotes around strings or keys, comments inside JSON (JSON does not support comments), or invisible characters copied from a document editor. Paste your JSON into the FixTools validator to pinpoint the exact line and character causing the error.
QCan I use an online JSON formatter for production API responses?
Online formatters are useful for development, debugging, and documentation. For production, your application should handle JSON parsing programmatically using built-in functions like JSON.parse() in JavaScript or json.loads() in Python. Use the online formatter when you need to inspect or share JSON manually.
QWhat is minified JSON and when should I use it?
Minified JSON removes all whitespace, indentation, and line breaks, reducing file size. It is harder to read but transfers faster over networks. Use minified JSON in API responses and configuration files deployed to production. Use formatted (beautified) JSON when writing or reviewing JSON manually.
QCan the JSON formatter handle very large files?
Browser-based formatters can handle most JSON files under 10 MB comfortably. Very large files (50 MB+) may slow down or crash the browser tab depending on your device's memory. For very large JSON files, use a command-line tool like jq or a code editor with a JSON plugin instead.
O. Kimani
Software Developer & Founder, FixTools
Building FixTools — a single destination for free, browser-based productivity tools. Every tool runs client-side: your files never leave your device.
About the authorRelated articles
How to Format and Validate JSON for APIs (With Examples)
Make your JSON API-ready: proper formatting, syntax validation, and common pitfalls that break requests. Free JSON formatter and validator in your browser.
Read articleDeveloper & WebHow to Minify HTML, CSS, and JavaScript Safely
Shrink your code for faster pages without breaking your site. What minification actually does, what to watch out for, and free tools to do it right.
Read article