← Back to Blog

What is JSON? A Complete Guide for Developers

Learn what JSON is, how it works, its syntax rules, and why it became the universal data exchange format. With examples and common mistakes.

JSON (JavaScript Object Notation) is a lightweight text format for storing and transporting data. It was created by Douglas Crockford in the early 2000s and has since become the most widely used data interchange format on the web — replacing XML in most modern APIs.

Despite its name, JSON is completely language-independent. Every major programming language can parse and generate JSON: Python, Java, Go, Rust, PHP, Ruby, C#, and of course JavaScript.

JSON Syntax Rules

JSON has only 6 data types and a very strict syntax. Understanding these rules prevents the most common bugs:

  • Strings — must use double quotes only. Single quotes are invalid.
  • Numbers — integers or decimals. No NaN or Infinity.
  • Booleans — lowercase true or false. Not True or True.
  • null — lowercase only. Not Null or NULL.
  • Arrays — ordered list in square brackets [...].
  • Objects — unordered key-value pairs in curly braces {...}. Keys must be strings.
JSON
{
  "name": "Alice",
  "age": 30,
  "active": true,
  "score": 98.5,
  "address": null,
  "tags": ["developer", "designer"],
  "location": {
    "city": "Mumbai",
    "country": "India"
  }
}

Common JSON Mistakes

MistakeWrongCorrect
Single quotes{'name': 'Alice'}{"name": "Alice"}
Trailing comma{"a":1, "b":2,}{"a":1, "b":2}
Comments// comment {"a":1}{"a":1} // not allowed
Undefined value{"x": undefined}{"x": null}
Uppercase boolean{"active": True}{"active": true}

JSON vs Other Formats

FeatureJSONXMLYAML
Human-readable✅ Yes⚠️ Verbose✅ Best
Comments❌ None✅ Yes✅ Yes
Type system✅ 6 types❌ Strings only✅ Rich
Browser native✅ Yes❌ No❌ No
API standard✅ Dominant⚠️ Legacy❌ Rare

Why JSON Won the Web

JSON won because of three things: it is natively supported in JavaScript (the language of the web), it is much smaller and faster than XML, and its syntax maps directly to data structures developers already use (dictionaries, lists, strings).

REST APIs use JSON. GraphQL uses JSON. LocalStorage uses JSON. Config files use JSON. Understanding JSON is non-negotiable for any modern developer.

Parsing JSON in Different Languages

JAVASCRIPT
// JavaScript
const obj = JSON.parse('{"name":"Alice"}');
const str = JSON.stringify(obj, null, 2);
PYTHON
# Python
import json
obj = json.loads('{"name":"Alice"}')
s = json.dumps(obj, indent=2)
💡
Use the JSON Formatter tool on DevToolkit to instantly beautify, validate, and explore any JSON — it catches syntax errors with exact line numbers.