Fundamentals

What is JSON? A Complete Guide for Developers

8 min read
January 22, 2026
what is json, json format, json example

JSON (JavaScript Object Notation) is the universal language of data exchange on the web. Whether you're fetching data from an API, storing configuration settings, or passing information between services, chances are you're working with JSON.

This guide covers everything you need to know about JSON: its syntax, data types, real-world examples, and best practices that will make you a more effective developer.

What is JSON?#

JSON stands for JavaScript Object Notation. Despite its name, JSON is completely language-independent and can be used with virtually any programming language including Python, Java, C#, Go, Ruby, and PHP.

JSON was derived from JavaScript but has become the dominant data format for web APIs, configuration files, and data storage. It was standardized as ECMA-404 in 2013.

Key characteristics of JSON:

  • Human-readable — Easy for developers to read and write
  • Machine-parseable — Quick for computers to parse and generate
  • Language-independent — Works with any programming language
  • Lightweight — Minimal syntax overhead compared to XML
example.jsonjson
{
  "name": "John Doe",
  "age": 30,
  "email": "john@example.com",
  "isActive": true,
  "roles": ["developer", "admin"]
}

JSON Syntax Rules#

JSON has strict syntax rules. Understanding these rules will help you avoid common parsing errors.

The 6 fundamental rules:

  1. Data is in key-value pairs — Keys must be strings in double quotes
  2. Data is separated by commas — No trailing commas allowed
  3. Curly braces hold objects{} for object containers
  4. Square brackets hold arrays[] for ordered lists
  5. Strings use double quotes only — Single quotes are invalid
  6. No comments allowed — JSON doesn't support // or /* */ comments

Common mistakes to avoid:

  • Using single quotes instead of double quotes
  • Adding trailing commas after the last item
  • Forgetting to quote property names
  • Using undefined or NaN (not valid JSON values)
syntax-example.jsonjson
{
  "string": "Hello World",
  "number": 42,
  "decimal": 3.14159,
  "boolean": true,
  "nullValue": null,
  "array": [1, 2, 3],
  "object": {
    "nested": "value"
  }
}

JSON Data Types#

JSON supports exactly six data types. Understanding these types is essential for working with JSON effectively.

TypeDescriptionExample
StringText in double quotes"Hello World"
NumberInteger or floating-point42, 3.14, -17
BooleanTrue or false valuetrue, false
NullEmpty/no valuenull
ArrayOrdered list of values[1, 2, 3]
ObjectKey-value pairs{"key": "value"}

Real-World JSON Examples#

Let's look at how JSON is used in real applications. These examples represent common patterns you'll encounter daily.

1. API Response (User Data)

This is a typical response from a REST API returning user information:

api-response.jsonjson
{
  "status": "success",
  "data": {
    "user": {
      "id": 12345,
      "username": "johndoe",
      "email": "john@example.com",
      "profile": {
        "firstName": "John",
        "lastName": "Doe",
        "avatar": "https://example.com/avatars/12345.jpg"
      },
      "createdAt": "2024-01-15T10:30:00Z",
      "permissions": ["read", "write", "delete"]
    }
  },
  "meta": {
    "requestId": "abc-123",
    "timestamp": "2026-01-22T12:00:00Z"
  }
}

JSON vs XML: Quick Comparison#

Before JSON became dominant, XML was the primary data exchange format. Here's why JSON won:

AspectJSONXML
ReadabilityCleaner, less verboseMore verbose with tags
File SizeSmaller (30-50% less)Larger due to closing tags
Parsing SpeedFasterSlower
Data TypesNative types (number, boolean)Everything is a string
CommentsNot supportedSupported
NamespacesNot supportedSupported

Working with JSON in Code#

Every major programming language has built-in or standard library support for JSON. Here are examples in the most common languages:

JavaScript (Native Support)

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

// Convert object to JSON string
const obj = { name: "Jane", age: 25 };
const jsonString = JSON.stringify(obj, null, 2);
console.log(jsonString);

Common Use Cases for JSON#

JSON is everywhere in modern software development. Here are the most common scenarios:

  • REST APIs — The standard format for API request/response bodies
  • Configuration Files — package.json, tsconfig.json, .eslintrc.json
  • Data Storage — MongoDB documents, localStorage, IndexedDB
  • Message Queues — Kafka, RabbitMQ, AWS SQS payloads
  • GraphQL — Response format for GraphQL queries
  • WebSockets — Real-time data exchange format
  • Logging — Structured logging (JSON logs)

Pro Tip: When working with large JSON files or complex structures, use a JSON formatter to make the data readable and catch syntax errors.

JSON Best Practices#

Follow these best practices to write clean, maintainable JSON:

  1. Use consistent naming conventions — camelCase is most common for JavaScript/TypeScript projects
  2. Keep nesting shallow — Deeply nested objects are hard to work with
  3. Use arrays for homogeneous data — All items should have the same structure
  4. Validate your JSON — Always validate before parsing in production
  5. Use ISO 8601 for dates — "2026-01-22T12:00:00Z" format is universally parseable
  6. Consider JSON Schema — For complex APIs, define a schema for validation

Frequently Asked Questions

What does JSON stand for?
JSON stands for JavaScript Object Notation. It was derived from JavaScript but is now language-independent and used across all programming languages.
Is JSON better than XML?
For most web applications, yes. JSON is more compact (30-50% smaller), faster to parse, and has native data types. However, XML is better when you need comments, namespaces, or document markup (like XHTML).
Can JSON have comments?
No, standard JSON does not support comments. If you need comments in configuration files, consider using JSON5, JSONC (JSON with Comments), or YAML instead.
What is the maximum size of a JSON file?
There is no official limit in the JSON specification. However, practical limits depend on the parser and available memory. Most parsers handle files up to several gigabytes, but for very large datasets, consider streaming parsers or alternative formats.
How do I validate JSON?
You can validate JSON using online tools like our JSON Formatter, or programmatically using JSON.parse() in JavaScript (it throws an error for invalid JSON), or json.loads() in Python.

Format & Validate Your JSON

Use our free JSON Formatter to beautify, validate, and minify your JSON data. Instant syntax highlighting and error detection.

Try JSON Formatter

Related Articles