JSON Formatting and Validation: A Complete Developer Guide
JSON (JavaScript Object Notation) is the most widely used data interchange format on the web. Every REST API, most configuration files, and many database systems use it. Understanding how to read, write, validate, and format JSON is a foundational skill for developers and marketers who work with web data.
What is JSON?
JSON is a lightweight text format for representing structured data. It was derived from JavaScript but is now language-independent — every major programming language has libraries for reading and writing it.
A basic JSON object looks like this:
{"name": "Tarumak Studio", "tools": 56, "free": true}JSON supports six data types: strings, numbers, booleans, null, arrays, and objects. Every valid JSON document is either an object ({}) or an array ([]).
JSON syntax rules
JSON is strict. Every character matters. The most common cause of invalid JSON is a single missing comma, brace, or quotation mark. Here are the non-negotiable rules:
- Keys must be in double quotes — single quotes are not valid JSON.
{"key": "value"}is valid.{'key': 'value'}is not. - Strings must be in double quotes — same rule applies to string values.
- No trailing commas — the last item in an object or array must not have a comma after it. This is the most common mistake.
- No comments — JSON does not support comments.
// commentor/* comment */are not valid. - Numbers need no quotes —
{"count": 56}not{"count": "56"}. - Booleans are lowercase —
trueandfalse, notTrueorFalse. - null is lowercase —
null, notNullorNULL.
The five most common JSON errors
1. Trailing comma — the single most common mistake:
{"name": "Alice", "age": 30,} ← invalid — remove the comma2. Single quotes instead of double quotes:
{'name': 'Alice'} ← invalid — use "name": "Alice"3. Unescaped special characters in strings:
{"quote": "She said "hello""} ← invalid — use "hello"4. Missing comma between items:
{"a": 1 "b": 2} ← invalid — needs a comma between pairs5. Numbers as strings when they should not be:
{"count": "56"} ← technically valid, but the value is a string not a number — if your API expects a number, this will failPretty printing vs minifying
JSON can be written in two ways: formatted (pretty-printed) or minified.
Formatted JSON uses newlines and indentation to make the structure readable to humans:
{
"name": "Tarumak",
"tools": 56
}Minified JSON removes all whitespace, reducing file size:
{"name":"Tarumak","tools":56}Use formatted JSON in source files, configuration files, and anywhere a human will read it. Use minified JSON in API responses, CDN payloads, and anywhere that byte count matters for performance. A JSON formatter/minifier tool handles either direction instantly.
Nested JSON and depth
JSON objects and arrays can contain other objects and arrays — this is called nesting:
{"user": {"name": "Alice", "skills": ["design", "dev"]}}There is no official limit to nesting depth in the JSON specification, but practical limits exist: most parsers handle up to 100 levels, and browsers can have stricter limits. If you find yourself with JSON nested 5+ levels deep, it is usually a sign the data structure should be redesigned.
JSON vs JSON5 vs JSONC
Standard JSON is deliberately strict. Two common extensions have emerged for human-edited configuration files:
- JSON5 — adds comments, trailing commas, single quotes, and unquoted keys. Used in some build tools.
- JSONC — JSON with Comments. Used in VS Code configuration files.
These are not valid JSON — do not send them to a standard JSON API. They are only appropriate in file formats whose parsers explicitly support them.
JSON in structured data (SEO)
JSON-LD (JSON Linked Data) is the recommended format by Google for embedding structured data in web pages. It is standard JSON wrapped in a script tag:
<script type="application/ld+json">{"@context": "https://schema.org", "@type": "Article"}</script>Errors in JSON-LD can cause Google to reject your structured data entirely. Using a JSON formatter to validate your schema markup before publishing avoids this.
Frequently asked questions
What is the difference between JSON and XML?
Both are text-based formats for structured data. JSON is more compact, easier to read, and natively parsed by JavaScript. XML supports comments, attributes, and mixed content but is more verbose. REST APIs now overwhelmingly use JSON. XML remains common in SOAP web services, RSS feeds, and some enterprise systems.
Can JSON contain JavaScript functions?
No. JSON is a data format only. Functions, undefined values, and special objects like Date are not valid JSON types. If you need to serialise a Date, store it as an ISO 8601 string: "2026-06-27T12:00:00Z".
How do I validate JSON in my browser?
Paste it into the JSON Formatter linked below — it will immediately flag any syntax error with the line number and error description. Alternatively, open your browser console and run JSON.parse(yourString) — if it throws, the JSON is invalid.
What does "unexpected token" mean in a JSON error?
It means the parser encountered a character it did not expect. The most common causes: a trailing comma after the last item, a single quote instead of a double quote, or an unescaped special character inside a string.