A JSON formatter makes raw, minified JSON instantly readable and validates it for errors — a daily essential for every developer. JSON (JavaScript Object Notation) is the universal language of APIs, configuration files, and data exchange. Every developer working with REST APIs, Node.js, Python data processing, or modern web development encounters JSON daily. Yet a single misplaced comma or missing quote can break everything — and error messages like "Unexpected token < at position 0" are notoriously cryptic.
This guide covers JSON from first principles: syntax rules, all data types, every common parse error and its fix, formatting options, and how JSON compares to XML. Whether you are a beginner seeing JSON for the first time or a senior developer who needs a quick reference, this is the complete guide.
Format and Validate Your JSON — Free
Paste any JSON and instantly get a formatted, validated, human-readable result. Errors highlighted with exact position. Minify option for production use.
What Is JSON and Why Do Developers Use It?
JSON (JavaScript Object Notation) is a lightweight text-based data interchange format. It was derived from JavaScript object syntax but is language-independent — JSON can be read and written by virtually every programming language including Python, Java, PHP, Go, Ruby, C#, and Swift.
A brief history
JSON was formalised by Douglas Crockford in the early 2000s as a simpler alternative to XML for transmitting data between web servers and browsers. It became the dominant API data format by 2010 and is now the default for REST APIs, NoSQL databases (MongoDB, Firebase), configuration files (package.json, tsconfig.json), and cloud services.
Why JSON won over XML
- Shorter — JSON uses less characters for the same data (no closing tags)
- Readable — human-readable even without formatting
- Native to JavaScript — JSON.parse() and JSON.stringify() are built into every browser
- Directly maps to data structures — objects, arrays, strings, numbers, booleans
// The same data in XML vs JSON:
// XML (42 characters)
<user><name>Priya</name><age>28</age></user>
// JSON (32 characters)
{"name": "Priya", "age": 28}JSON Syntax Rules: The Complete Reference
JSON has exactly six data types and a strict set of syntax rules. Violating any rule produces a parse error.
The six JSON data types
| Type | Example | Notes |
|---|---|---|
| String | "Hello, World" | Must use double quotes (not single quotes) |
| Number | 42, 3.14, -7, 1.5e10 | No hex, no NaN, no Infinity |
| Boolean | true, false | Lowercase only |
| Null | null | Lowercase only; represents absent value |
| Array | ["a", 1, true] | Ordered list; can mix types |
| Object | {"key": "value"} | Unordered key-value pairs; keys must be strings |
Strict JSON rules (vs JavaScript objects)
- All keys must be in double quotes —
{"name": "value"}✓ vs{name: "value"}✗ - No trailing commas —
{"a": 1, "b": 2,}is invalid JSON - No comments — JSON does not support // or /* */ comments
- No undefined — JavaScript's undefined is not a valid JSON type
- No functions — JSON is pure data, not code
- Strings must use escaped special characters: \n (newline), \t (tab), \\ (backslash), \" (quote)
JavaScript allows trailing commas, single quotes, and unquoted keys in object literals — but these are not valid JSON. The safest way to check: JSON.parse(yourString) in your browser console. If it throws, it is not valid JSON.
Common JSON Errors and How to Fix Them
These are the most frequently encountered JSON parse errors with their causes and fixes. Save this as your debugging reference.
| Error Message | Cause | Fix |
|---|---|---|
| Unexpected token < at position 0 | Server returned HTML (error page) instead of JSON | Check your API response; look for HTTP 404/500 status codes |
| Unexpected token , (trailing comma) | Trailing comma after last property or array element | Remove the comma after the last item |
| Unexpected token ' (single quotes) | Single quotes used instead of double quotes | Replace all single quotes with double quotes around strings and keys |
| Unexpected end of JSON input | JSON string is truncated or incomplete | Check if the full response was received; look for missing closing brackets |
| Unexpected token u in JSON at position 0 | Trying to JSON.parse(undefined) | Check that your variable actually contains JSON before parsing |
| Property names must be double-quoted | Unquoted key in object | Add double quotes around all object keys |
| Bad escape sequence | Invalid escape character in string | Use \n for newline, \t for tab, \\ for backslash |
Quick fix workflow
- Paste your JSON into ToolsArena's JSON Formatter
- The validator highlights the exact line and character position of the error
- Use the error table above to identify and fix the issue
- Re-validate until the green "Valid JSON" indicator appears
If your JSON starts with "<!DOCTYPE html>" or "<html>", your API is returning an HTML error page instead of JSON. This is a server-side issue — check your API endpoint URL and authentication credentials, not your JSON syntax.
Pretty-Print vs Minified JSON: When to Use Each
JSON can be formatted in two ways, each with distinct use cases.
Pretty-printed JSON (human-readable)
{
"user": {
"name": "Priya Sharma",
"age": 28,
"roles": ["admin", "editor"]
}
}
Use for: Debugging, documentation, config files, code reviews, API documentation, learning.
Minified JSON (machine-efficient)
{"user":{"name":"Priya Sharma","age":28,"roles":["admin","editor"]}}
Use for: API responses in production, storing JSON in databases, transmitting over the network where payload size matters.
Size difference
For typical API responses, minification reduces JSON size by 15–30%. For large datasets (10,000+ records), this can meaningfully reduce transfer time and server bandwidth costs.
Indentation: 2 spaces vs 4 spaces vs tabs
This is a style preference with no technical impact. JavaScript/Node.js convention: 2 spaces. Python (json.dumps): 4 spaces. GitHub uses 2 spaces for JSON config files. Pick one and stay consistent within a project.
JSON5 and JSONC (JSON with Comments) are supersets of JSON that allow trailing commas, comments, and unquoted keys. They are used in config files (VS Code's settings.json, TypeScript's tsconfig.json) but must be parsed with special parsers — they are not valid JSON. Never use JSON5 for API communication.
JSON vs XML: Which Should You Use?
JSON and XML both represent structured data but have different strengths. Here is the definitive comparison.
| Feature | JSON | XML |
|---|---|---|
| Verbosity | Compact — no closing tags | Verbose — opening and closing tags for every element |
| Readability | Easier for developers | More readable for business stakeholders |
| Data types | String, number, boolean, null, array, object | All values are strings; type must be defined in schema |
| Comments | Not supported | Supported (<!-- comment -->) |
| Attributes | Not supported (use nested objects) | Supported (element attributes) |
| Schema validation | JSON Schema (less universal) | XSD (mature, widely supported) |
| Namespace support | Not supported | Full namespace support |
| Browser parsing | Native (JSON.parse) | Requires DOMParser or external library |
| Use in modern APIs | Dominant (REST, GraphQL) | Legacy enterprise (SOAP, legacy banking) |
| Use in config files | Very common | Less common (Maven, Spring, Ant) |
When to choose XML over JSON
- Integrating with legacy enterprise systems (SAP, older banking APIs) that require XML/SOAP
- Documents that need rich metadata and mixed content (text with inline markup)
- Contexts requiring XSD schema validation and namespaces
- RSS/Atom feeds (XML-based by standard)
For everything else — REST APIs, configuration files, data storage, modern web applications — choose JSON.
How to Use the Tool (Step by Step)
- 1
Open ToolsArena JSON Formatter
Navigate to the free JSON formatter and validator — no account or download required.
- 2
Paste your JSON
Paste your raw JSON text (minified, formatted, or broken) into the input area.
- 3
Click Format / Validate
Press the Format button. The tool validates your JSON and pretty-prints it with consistent 2-space indentation.
- 4
Read the error report
If your JSON is invalid, the error message shows the exact line and character position of the problem.
- 5
Copy or download the result
Use the Copy button to copy the formatted JSON to clipboard, or use the Minify option to get compact JSON for production use.
Frequently Asked Questions
What is a JSON formatter?+−
A JSON formatter (also called a JSON beautifier or JSON pretty-printer) takes raw JSON text — whether minified, improperly indented, or on a single line — and reformats it with consistent indentation and line breaks to make it human-readable. A good formatter also validates the JSON and reports any syntax errors.
How do I fix a JSON parse error?+−
Common fixes: (1) Replace single quotes with double quotes around all keys and string values; (2) Remove trailing commas after the last item in objects and arrays; (3) Add missing commas between items; (4) Ensure all strings are properly closed with double quotes; (5) If the error says "unexpected token <", your API returned HTML instead of JSON — check your endpoint URL and credentials.
What is the difference between JSON and JavaScript objects?+−
JSON is a text-based data format with strict rules: all keys must be double-quoted, no trailing commas, no comments, no functions, no undefined values. JavaScript object literals are more lenient: keys can be unquoted, single quotes are allowed, trailing commas are valid in modern JS. JSON is a subset of valid JavaScript syntax but not all valid JavaScript objects are valid JSON.
What does JSON pretty print mean?+−
Pretty-printing (or formatting/beautifying) JSON means reformatting a compact or poorly indented JSON string into a human-readable form with consistent indentation (typically 2 or 4 spaces) and line breaks. For example, {"name":"John","age":30} becomes a multi-line version with each key-value pair on its own line and proper nesting indentation.
How do I validate JSON online?+−
Paste your JSON into ToolsArena's JSON Formatter. If the JSON is valid, you will see a green "Valid JSON" indicator. If invalid, the error message will show the exact position and type of syntax error. You can also validate programmatically: in JavaScript use try { JSON.parse(str); } catch(e) { console.error(e); }, or in Python use json.loads(str) inside a try/except block.
Is JSON case-sensitive?+−
Yes. JSON keys and string values are case-sensitive. {"Name": "Priya"} and {"name": "Priya"} are different objects with different keys. Boolean values (true, false) and null must be lowercase — "True" and "NULL" are not valid JSON.
Can JSON have comments?+−
No. Standard JSON does not support comments. If you try to add // or /* */ comments to JSON, it will fail to parse. This was a deliberate design choice by Douglas Crockford to keep JSON purely as a data format, not a configuration language. If you need comments in config files, use JSONC or JSON5 (but note these require special parsers).
Format and Validate Your JSON — Free
Paste any JSON and instantly get a formatted, validated, human-readable result. Errors highlighted with exact position. Minify option for production use.
Open JSON FormatterRelated Guides
PDF Compressor Guide
Everything you need to know to shrink PDFs for email, web upload, and sharing — on every platform, without expensive software.
Image Compression Guide
Everything web developers, bloggers, and designers need to know about compressing images for fast, beautiful websites.
QR Code Generator Guide
Everything you need to know about QR codes — how they work, creative use cases, design tips, and how to create them for free.