JSON Is Stricter Than It Looks
JSON (JavaScript Object Notation) looks close enough to a JavaScript object that it's tempting to treat the two as interchangeable — but JSON is a much stricter, standalone data format with its own rules, and a document that would run perfectly fine as JavaScript code can still be completely invalid JSON.
That gap catches people constantly. JavaScript allows single-quoted strings, unquoted keys, trailing commas, and comments — JSON allows none of those. A parser reading JSON doesn't guess at intent or gracefully skip a small mistake; a single misplaced comma or an unquoted key anywhere in a large document makes the entire thing fail to parse, which is exactly why a fast, precise validator is worth having on hand.
At a glance:
• Object keys and all string values must use double quotes — never single quotes
• Trailing commas after the last item in an object or array are not allowed
• Comments of any kind are not part of the JSON specification
• Only six data types exist in JSON: object, array, string, number, boolean, and null
JSON Validator & Formatter
Structure Tree
What a Parser Is Actually Checking
A JSON parser checks, in order:
Every brace and bracket opened is eventually closed, in the right order
Every key and string is wrapped in double quotes
Every value is a valid type, with no trailing commas anywhere
Why One Error Breaks the Whole Document
A JSON parser reads character by character, building up a structure as it goes — it doesn't have a concept of "close enough." The moment it hits something that doesn't fit the grammar (an unexpected comma, a missing quote, an unclosed bracket), it stops immediately and reports exactly where things went wrong, rather than trying to guess what you meant and continue.
Worked Example
Given: {"active": true,}
Step 1: The parser reads the opening brace and the key-value pair fine
Step 2: It hits the comma after "true" and expects another key-value pair to follow
Step 3: Instead it finds the closing brace immediately — a trailing comma with nothing after it
Result: Parsing fails right at that comma, even though everything before it was perfectly valid
The Errors That Show Up Again and Again
Common JSON Mistakes
| Invalid | Valid |
|---|---|
| {name: "Al"} | {"name": "Al"} |
| {'name': 'Al'} | {"name": "Al"} |
| [1, 2, 3,] | [1, 2, 3] |
| // a comment | (remove entirely) |
Where JSON Validation Actually Saves Time
Debugging API Requests and Responses: A malformed request body or an unexpected API response is one of the most common causes of integration bugs — validating the raw payload quickly rules out (or confirms) a syntax problem before digging into application logic.
Configuration File Editing: Files like package.json or tsconfig.json are strict JSON, and a single stray comma from manual editing can silently break an entire build — a quick validation pass catches it before it causes a confusing downstream error.
Data Import and Export: Before importing a JSON file into a database or application, validating it up front avoids partial imports or cryptic failures partway through processing a large file.
Webhook Payload Testing: Developers testing webhook integrations often hand-write sample payloads to simulate incoming events, where small syntax mistakes are easy to introduce and just as easy to catch with a validator first.
Generating Test Fixtures: QA and test automation frequently rely on hand-maintained JSON fixture files, which benefit from the same quick validation pass any other manually edited JSON does.
Learning JSON Structure: For anyone new to APIs or data formats, visualizing a document's nested structure as a tree makes it much easier to understand how objects, arrays, and values relate to each other than reading dense, unformatted text.
Writing Valid JSON by Hand
✓ Always use double quotes, never single: This is the single most common cause of invalid JSON when converting from JavaScript object literal syntax, which happily allows single quotes.
✓ Check your last item before closing a bracket: A trailing comma is easy to leave behind after deleting the last item in a list — always check the item just before a closing } or ].
✓ Numbers can't have leading zeros: 007 is invalid JSON; if you need to preserve leading zeros (like a zip code), store the value as a string instead — "007".
✓ undefined and NaN aren't valid JSON values: Unlike JavaScript, JSON has no concept of undefined and no NaN — use null instead when a value is genuinely absent.
✓ Keys are always strings, even for numeric-looking data: {1: "a"} is invalid — it must be {"1": "a"}, since JSON object keys are always strings by definition.
✓ Validate before you parse in code: Wrapping JSON.parse() in a try/catch handles invalid input gracefully in an application, but validating suspect data up front during development saves time tracking down where a bad payload actually originated.
A Format Born From a Simpler Idea Than XML
Douglas Crockford Popularized It in the Early 2000s: While the underlying idea of using JavaScript's own object literal syntax as a lightweight data format existed informally before, Douglas Crockford is widely credited with formalizing and popularizing JSON as a standalone specification in the early 2000s, along with creating json.org to document it.
Designed to Be a Simpler Alternative to XML: At the time JSON emerged, XML was the dominant format for structured data exchange, but its verbosity and complexity (namespaces, schemas, closing tags for everything) made it heavier than many web applications actually needed — JSON offered a leaner alternative that mapped naturally onto JavaScript's own data structures.
Standardized Independently of JavaScript: Despite its name and syntax inheritance, JSON was eventually formalized as its own language-independent standard (through both an RFC and an ECMA specification), which is why virtually every programming language today has a JSON parser, not just JavaScript.
Became the Default Language of Web APIs: By the 2010s, JSON had largely displaced XML as the standard format for REST API request and response bodies, a shift driven heavily by its smaller size, easier parsing, and natural fit with JavaScript-heavy web applications.
Frequently Asked Questions
Q: Is a JavaScript object literal the same as JSON?
No — they look similar but follow different rules. JavaScript object literals allow single quotes, unquoted keys, trailing commas, comments, and functions as values; strict JSON allows none of those.
Q: Why isn't a trailing comma allowed in JSON?
It's simply not part of the specification — the JSON grammar defines exactly how items in an object or array must be separated, and a comma with nothing following it doesn't match that grammar.
Q: Can JSON contain comments?
No. The JSON specification has no provision for comments of any kind — some tools support a relaxed superset (like JSON5 or JSONC) that allows them, but strict JSON does not.
Q: What's the difference between JSON and XML?
Both represent structured data, but JSON uses a more compact syntax based on objects and arrays, while XML uses nested tags with optional attributes — JSON is generally more compact and easier to parse, while XML offers features like namespaces and schema validation that JSON lacks natively.
Q: What is JSON Schema?
It's a separate specification for describing the expected structure of a JSON document — what keys should exist, what types they should be, which are required — used to validate not just that JSON is syntactically correct, but that it matches a specific expected shape.
Q: Is JSON tied to JavaScript specifically?
No — despite the name, JSON is a language-independent data format with parsers available in essentially every programming language, and it's used constantly in contexts that have nothing to do with JavaScript at all.