What is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data format used to store and transmit structured information. Despite the word "JavaScript" in its name, JSON is completely language-independent and is supported natively by virtually every programming language in use today — Python, C#, Java, Go, Rust, Ruby, and more.
Douglas Crockford standardised JSON in the early 2000s as a simpler alternative to XML. It was formally specified in RFC 8259 and is now the default format for REST APIs, configuration files, log data, and inter-service communication across the industry.
JSON syntax — the six value types
Every valid JSON document is built from exactly six value types:
- String — text wrapped in double quotes:
"Hello, world" - Number — integer or floating point, no quotes:
42,3.14,-7 - Boolean — lowercase only:
trueorfalse - Null — represents an absent value:
null - Object — an unordered set of key-value pairs inside
{ } - Array — an ordered list of values inside
[ ]
A complete JSON document looks like this:
{
"name": "Pankaj Kumar",
"role": "Senior Software Engineer",
"active": true,
"score": 98.5,
"tags": ["blazor", "dotnet", "csharp"],
"address": {
"city": "Bangalore",
"country": "India"
},
"notes": null
}
Minified vs formatted JSON
Minified JSON strips all whitespace and newlines to reduce file size, making it ideal for network transmission. Formatted JSON (also called pretty-printed) adds consistent indentation and line breaks, making it human-readable for debugging and code review.
The same data in both forms:
// Minified — 48 bytes
{"name":"Pankaj","city":"Bangalore"}
// Formatted — easier to read
{
"name": "Pankaj",
"city": "Bangalore"
}
Use minified JSON in HTTP responses and log files where size matters. Use formatted JSON when writing config files, committing to source control, or reviewing data during development.
How to validate JSON
JSON validation checks that your document conforms to the JSON specification — correct brackets, quoted keys, valid value types, no trailing commas, and no comments. A validator reports the exact line and character where a problem occurs.
Common validation approaches:
- Online formatters and validators (like the DevToolsHub JSON Formatter)
- Browser DevTools console:
JSON.parse(yourString)throws a SyntaxError on invalid JSON - Language-native parsers:
System.Text.Jsonin C#,json.loads()in Python - IDE plugins that highlight JSON errors inline
The most common JSON mistakes
These four mistakes account for the vast majority of JSON parse errors:
- Trailing commas — JSON does not allow a comma after the last item in an object or array. This is valid in JavaScript but strictly forbidden in JSON:
{"a":1, "b":2,}is invalid. - Single quotes — all strings and all keys must use double quotes.
{'name': 'Pankaj'}is JavaScript, not JSON. - Comments — standard JSON does not support comments. If you need comments in a config file, consider JSON5 or JSONC (used by VS Code) — but plain JSON has no
//or/* */. - Unquoted keys — every object key must be a quoted string.
{name: "Pankaj"}is invalid JSON.
JSON vs XML
Before JSON became dominant, XML was the standard for data exchange. JSON replaced it in most web API contexts for three reasons: it is more compact (less verbose), it maps directly to data structures in every language, and it is easier for both humans and machines to parse. XML is still used in enterprise systems, document formats (DOCX, SVG), and SOAP web services, but for REST APIs, JSON is the clear choice.
JSON in real projects
You encounter JSON constantly in modern development:
- REST API responses — virtually every public API (GitHub, Stripe, Google Maps) returns JSON
- Configuration files —
package.json,appsettings.json,tsconfig.json,launch.json - Data storage — PostgreSQL, MongoDB, and SQL Server all support native JSON columns
- Logging — structured log formats like Serilog and Logstash use JSON for machine-parseable output
- Inter-service messaging — event payloads in Kafka, RabbitMQ, and Azure Service Bus are typically JSON
Quick reference
- Keys must be double-quoted strings
- No trailing commas after the last element
- No comments allowed in standard JSON
- Strings must use double quotes, not single quotes
- Numbers do not need quotes
- Booleans are lowercase:
true/false - Missing or absent values use
null, notundefined