What Is JSON? A Complete Developer's Guide to JSON Formatting and Validation
Learn what JSON is, how it works, common JSON errors and how to fix them, and how to format and validate JSON instantly using a free browser-based tool.
What Is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. It was originally derived from JavaScript object syntax, but today it is language-independent — virtually every programming language can read and write JSON. It became the dominant format for exchanging data between web clients and servers, replacing XML in most modern web APIs.
JSON is built on two universal data structures that exist in some form in virtually every programming language:
- Objects — A collection of name/value pairs (also called a dictionary, hash table, or associative array in other languages)
- Arrays — An ordered list of values
These two structures, combined with six primitive value types (string, number, boolean, null, object, array), give JSON enough expressive power to represent virtually any data structure while remaining simple enough for humans to read and write.
JSON Syntax: The Complete Rules
JSON has a small, precise set of syntax rules. Every JSON error comes from violating one of these rules:
Strings Must Use Double Quotes
In JSON, strings must always be enclosed in double quotes. Single quotes are not valid JSON.
✅ Valid: {"name": "DocsConverter"}
❌ Invalid: {'name': 'DocsConverter'}
Keys Must Be Strings
Every key in a JSON object must be a quoted string. Unlike JavaScript objects, which allow unquoted keys, JSON requires quotes around every key.
✅ Valid: {"count": 42}
❌ Invalid: {count: 42}
No Trailing Commas
This is the most common JSON error. JSON does not allow a comma after the last item in an object or array. Many developers write trailing commas habitually from JavaScript (where they're allowed), but they break JSON.
✅ Valid: {"a": 1, "b": 2}
❌ Invalid: {"a": 1, "b": 2,}
No Comments
JSON does not support comments of any kind — no // single-line comments and no /* */ block comments. If you need to add documentation to a JSON config file, look into JSONC (JSON with Comments) or JSON5, which are supersets that support comments but aren't standard JSON.
Numbers Cannot Have Leading Zeros
The number 007 is not valid JSON. Numbers must not have leading zeros unless the number is literally 0 or a decimal (0.7 is valid; 07 is not).
Values Can Be One of Six Types
| Type | Example |
|---|---|
| String | "Hello World" |
| Number | 42, 3.14, -1, 1.5e10 |
| Boolean | true, false |
| Null | null |
| Object | {"key": "value"} |
| Array | [1, 2, 3] |
Note that undefined, NaN, Infinity, and Date objects are not valid JSON values — they are JavaScript-specific and have no JSON equivalent.
The Difference Between Formatting and Validating JSON
These two operations are related but distinct:
JSON Validation
Validation checks whether a string is syntactically valid JSON — does it follow all the rules above? A validator parses the string and tells you either "this is valid JSON" or identifies the exact location of the syntax error. Validation gives you a binary answer: valid or not.
JSON Formatting (Beautifying)
Formatting takes valid JSON and renders it with consistent indentation, line breaks, and spacing to make it human-readable. Minified JSON (with all whitespace removed) and formatted JSON contain identical data — only the presentation differs. Formatting is useful when you're reading or debugging JSON; minification is useful when you're transmitting JSON over a network (smaller file size, faster transfer).
JSON Minification
Minification removes all unnecessary whitespace, line breaks, and indentation from JSON. A 10 KB formatted JSON file might minify to 4 KB. For JSON transmitted in API responses served millions of times per day, this matters significantly for bandwidth costs and response times.
Common JSON Errors and How to Fix Them
Error: Unexpected token '
Cause: Single quotes used instead of double quotes for strings or keys.
Fix: Replace all single quotes with double quotes. Find and replace ' with ", being careful not to accidentally create escaped quotes within string values.
Error: Unexpected token at position X
Cause: Most commonly a trailing comma. Could also be a missing colon between key and value, or a missing comma between items.
Fix: Navigate to the character position indicated. Look for a comma before a closing bracket ] or brace } (trailing comma), or check that colons and commas are correctly placed.
Error: Unexpected end of JSON input
Cause: The JSON is incomplete — typically a missing closing bracket, brace, or quote. Happens when JSON is truncated (partial API response, incomplete copy-paste).
Fix: Count your opening and closing brackets and braces. Every { needs a } and every [ needs a ]. Our formatter will highlight the unclosed structure.
Error: Property names must be strings
Cause: An unquoted key in an object, like {name: "value"} instead of {"name": "value"}.
Fix: Add double quotes around every key.
How to Format JSON Using DocsConverter
Our free JSON Formatter and Validator instantly beautifies, validates, and minifies JSON in your browser. No uploads, no sign-in, no size limits for typical JSON files.
- Open the tool — Navigate to docsconverter.in/json-formatter. No account required.
- Paste your JSON — Paste any JSON string into the input area. This could be an API response, a config file, or any JSON string you need to inspect.
- Validate instantly — The tool immediately tells you if your JSON is valid. If there's an error, it highlights the problematic location and explains what's wrong.
- Format or minify — Click Format to add proper indentation and line breaks. Click Minify to remove all whitespace for compact storage or transmission.
- Copy the result — Copy the formatted or minified JSON to your clipboard with a single click.
JSON in Real-World Development
REST API Responses
The overwhelming majority of modern REST APIs return JSON responses. When you make a request to an API — whether it's a weather API, a payment API, or your own backend — the response body almost always contains JSON. Being able to quickly format and understand API responses is a fundamental developer skill.
Configuration Files
Many development tools use JSON for configuration: package.json (Node.js projects), tsconfig.json (TypeScript), .eslintrc.json (ESLint), launch.json (VS Code debug config). When these files have syntax errors, your build tools fail with cryptic messages — a JSON validator quickly identifies the exact problem.
Data Storage
NoSQL databases like MongoDB store documents in a BSON format (Binary JSON). Firebase's Realtime Database and Firestore use JSON-compatible structures. When you export data from these databases, you typically get JSON files that need to be inspected, reformatted, or transformed.
Local Storage and Cookies
Browser localStorage can only store strings. Developers commonly JSON.stringify() objects before storing them and JSON.parse() when retrieving them. Debugging localStorage often means reading and formatting JSON strings.
JSON vs. XML vs. YAML — When to Use Each
| Format | Readability | Verbosity | Best For |
|---|---|---|---|
| JSON | Good | Low | Web APIs, JavaScript apps, data exchange |
| XML | Poor | Very high | Legacy enterprise systems, SOAP APIs, documents |
| YAML | Excellent | Very low | Configuration files, Kubernetes, CI/CD pipelines |
| TOML | Excellent | Low | Application config (Rust, Hugo) |
JSON's combination of broad language support, compact syntax, and direct mapping to JavaScript data structures made it the default choice for web APIs. YAML's lack of quotes and support for comments makes it more comfortable for hand-written configuration files.
Frequently Asked Questions About JSON
What does JSON stand for?
JSON stands for JavaScript Object Notation. Despite the name, JSON is language-independent and is used with Python, Java, C#, Go, Ruby, PHP, and virtually every other programming language.
What is the difference between JSON and JavaScript objects?
JSON is a text format with strict syntax rules. JavaScript objects are runtime data structures with more flexible syntax (they can have unquoted keys, trailing commas, comments, and methods). JSON.parse() converts a JSON string into a JavaScript object; JSON.stringify() converts a JavaScript object into a JSON string.
How do I validate JSON online for free?
Use DocsConverter's JSON Formatter at docsconverter.in/json-formatter. Paste your JSON and it instantly validates it, highlights errors, and shows you the exact location and type of any syntax problem.
Can JSON contain functions?
No. JSON is a pure data format — it cannot represent functions, methods, or executable code. If JSON.stringify() encounters a function in a JavaScript object, it silently omits that property from the output.
What is the maximum size for a JSON file?
The JSON specification has no size limit. Practical limits depend on the parser's memory — browser-based parsers can typically handle JSON files up to hundreds of megabytes. Our JSON Formatter works with large JSON files within your browser's memory constraints.
Why does my JSON work in JavaScript but fail in a JSON validator?
JavaScript is more permissive than JSON. JS allows single quotes, trailing commas, unquoted keys, and comments in object literals — none of which are valid JSON. Code that uses JavaScript object syntax may not be valid JSON even if it works in a JS context.