Skip to content
What is JSON — Simple Explanation with Examples

What is JSON — Simple Explanation with Examples

DodaTech Updated Jun 20, 2026 5 min read

JSON (JavaScript Object Notation) is a lightweight, text-based data format for storing and exchanging structured data between systems, designed to be both human-readable and machine-parseable.

In this guide, you’ll learn how JSON works, how to read and write JSON in Python and JavaScript, and why it has become the universal data format for APIs. Whether you’re building a web app or integrating third-party services, JSON is unavoidable.

Why JSON Exists — The Problem It Solves

Before JSON, web applications exchanged data primarily using XML. XML is powerful but verbose — a simple key-value pair can take multiple lines. This made parsing slow and debugging painful. JSON was created in 2001 by Douglas Crockford as a simpler alternative that:

  • Uses less bandwidth (smaller payload size)
  • Is trivial to parse in JavaScript (eval before the spec)
  • Maps naturally to common data structures (objects, arrays)

JSON vs XML

FeatureJSONXML
ReadabilityCleanVerbose
Data typesNative (string, number, bool, null)All text
Array supportNative []Requires wrapping elements
Parsing speedFastSlower
Browser supportNative (JSON.parse)Requires XML parser
Metadata/attributesNoYes (attributes, namespaces)
// JSON — 102 bytes
{
  "name": "Alice",
  "age": 30,
  "active": true,
  "tags": ["admin", "editor"]
}
<!-- XML — 195 bytes -->
<user>
  <name>Alice</name>
  <age type="integer">30</age>
  <active type="boolean">true</active>
  <tags>
    <tag>admin</tag>
    <tag>editor</tag>
  </tags>
</user>

The Analogy — Fill-in Form

JSON is like a fill-in form. Each field has a label (the key) and a space to write information (the value). A single form might have text fields, number fields, checkboxes (booleans), and sections that repeat (arrays).

If you imagine passing this form between two people — one fills it out, the other reads it — JSON is the standardized way to structure that form so both sides agree on how it looks.

JSON Structure

JSON supports exactly six data types:

TypeExampleDescription
String"hello"Double-quoted Unicode text
Number42 or 3.14Integer or floating-point
Booleantrue / falseLogical values
NullnullEmpty/absent value
Array[1, 2, 3]Ordered list (brackets)
Object{"key": "value"}Key-value map (braces)

Rules

  • Keys must be double-quoted strings ("name", not name or 'name')
  • No trailing commas allowed
  • No comments (JSON is data-only)
  • Strings use double quotes only
  • The outermost value must be an object, array, or literal

Example Document

{
  "id": 42,
  "title": "What is JSON",
  "published": true,
  "wordCount": 1500,
  "tags": ["programming", "json", "tutorial"],
  "author": {
    "name": "DodaTech",
    "email": "author@dodatech.com",
    "active": true
  },
  "metadata": null
}

JSON in APIs

Most modern REST APIs use JSON as their primary data format.

Request Example

POST /api/users HTTP/1.1
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "s3cret!",
  "name": "John Doe"
}

Response Example

HTTP/1.1 201 Created
Content-Type: application/json

{
  "id": 101,
  "email": "user@example.com",
  "name": "John Doe",
  "createdAt": "2026-06-20T10:30:00Z"
}

Parsing JSON in Python

import json

# Parse JSON string
json_str = '{"name": "Alice", "age": 30}'
data = json.loads(json_str)  # Returns Python dict
print(data["name"])  # Alice
print(data["age"])   # 30

# Convert Python to JSON
person = {
    "name": "Bob",
    "age": 25,
    "skills": ["Python", "JSON"]
}
json_output = json.dumps(person, indent=2)
print(json_output)

Expected output:

{
  "name": "Bob",
  "age": 25,
  "skills": [
    "Python",
    "JSON"
  ]
}

Working with JSON Files

import json

# Read from file
with open("config.json") as f:
    config = json.load(f)

# Write to file
config["version"] = "2.0"
with open("config.json", "w") as f:
    json.dump(config, f, indent=2)

Parsing JSON in JavaScript

// Parse JSON string
const jsonStr = '{"name": "Alice", "age": 30}';
const data = JSON.parse(jsonStr);
console.log(data.name);  // Alice
console.log(data.age);   // 30

// Convert object to JSON
const person = {
  name: "Bob",
  age: 25,
  skills: ["JavaScript", "JSON"]
};
const jsonOutput = JSON.stringify(person, null, 2);
console.log(jsonOutput);

Expected output: Same as Python example above.

JSON Validation Tools

Before using JSON in production, validate it:

  • Online: JSONLint.com, JSON Schema Validator
  • CLI: python -m json.tool file.json
  • VS Code: Built-in JSON validation (red squiggles for errors)
# Validate a JSON file from command line
echo '{"valid": true}' | python -m json.tool
# Output: {
#     "valid": true
# }

echo '{invalid}' | python -m json.tool
# Output: Expecting property name enclosed in double quotes: line 1 column 2

Common Use Cases

1. REST API communication

JSON is the standard format for request/response bodies in modern web APIs. Services like GitHub, Stripe, and Twilio all use JSON.

2. Configuration files

npm’s package.json, VS Code’s settings.json, and Docker Compose files are all JSON (or JSON-compatible like JSONC with comments).

3. Data storage

NoSQL databases like MongoDB store documents in BSON (a binary variant of JSON). IndexedDB and localStorage in browsers use JSON for structured data.

4. Real-time data streaming

WebSocket messages are often JSON-encoded. Chat apps, live dashboards, and collaborative editors exchange JSON frames.

5. Machine-to-machine communication

IoT devices send sensor readings as JSON. Cloud functions parse JSON from event triggers. Webhooks deliver events as JSON payloads.

FAQ

What does JSON stand for?

JavaScript Object Notation. Despite the name, it is language-independent and supported by virtually every programming language.

Can JSON have comments?

No. The JSON specification explicitly excludes comments. Extensions like JSONC (used by VS Code) add comments but are not standard JSON.

What is the difference between JSON and a JavaScript object?

JSON is a string representation. JavaScript objects are in-memory data structures. JSON.parse() converts a JSON string to a JS object. JSON.stringify() converts in reverse.

Is JSON faster than XML?

Yes. JSON is less verbose, so parsing is faster and payload sizes are smaller. This matters for mobile apps and high-traffic APIs where bandwidth matters.

What is the maximum JSON file size?

There is no official limit. Practical limits depend on the parser (Python’s json module loads entire files into memory) and available RAM.

Related Terms

REST API, XML, YAML, API, WebSocket

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro