Namso · Random IBAN · Random IMEI · Random MAC · UUID Generator · JSON Formatter · Hex to ASCII · Base64 Decode · Hash Generator · Password Gen · Lorem Ipsum

What is JSON? The Complete Guide

Try the JSON Formatter

What is JSON? The Complete Guide for Beginners and Developers


If you've worked with web APIs, configuration files, or any modern web application, you've encountered JSON. It's everywhere — and for good reason.

JSON (JavaScript Object Notation) is a lightweight data format that's easy for humans to read and write, and easy for machines to parse and generate. It's become the de facto standard for data interchange on the web.

Let's break down everything you need to know.

What Does JSON Stand For?

JavaScript Object Notation

Despite the name, JSON isn't limited to JavaScript. It's a language-independent format supported by virtually every programming language: Python, Java, C#, Ruby, PHP, Go, Rust — you name it.

The "JavaScript" part comes from its syntax, which is based on JavaScript object literals. But JSON is purely a data format — no functions, no methods, no executable code.

JSON Syntax Rules

JSON has strict syntax rules. Unlike JavaScript, there's no flexibility here. Break a rule, get invalid JSON.

The Basics

{
  "name": "Alice",
  "age": 30,
  "isActive": true,
  "email": null,
  "hobbies": ["reading", "coding", "hiking"]
}

Rule 1: Double Quotes Only

Strings and keys must use double quotes ("). Single quotes don't work.

// ✅ Valid
{"name": "Alice"}

// ❌ Invalid - single quotes
{'name': 'Alice'}

// ❌ Invalid - unquoted key
{name: "Alice"}

Rule 2: No Trailing Commas

The last item in an object or array cannot have a trailing comma.

// ✅ Valid
{"a": 1, "b": 2}

// ❌ Invalid - trailing comma
{"a": 1, "b": 2,}

Rule 3: No Comments

JSON does not support comments. Not single-line, not multi-line.

// ❌ Invalid
{
  "name": "Alice" // this is not allowed
}

If you need comments, consider JSONC (JSON with Comments) or YAML — but standard JSON won't accept them.

Rule 4: Specific Data Types Only

JSON supports exactly six data types. Nothing else.

JSON Data Types

1. String

Text wrapped in double quotes. Supports escape sequences.

{
  "simple": "Hello, World!",
  "escaped": "Line 1\nLine 2",
  "unicode": "Emoji: \u263A",
  "quotes": "She said \"hello\""
}

Escape sequences: \" \\ \/ \b \f \n \r \t \uXXXX

2. Number

Integer or floating-point. No quotes.

{
  "integer": 42,
  "negative": -17,
  "float": 3.14159,
  "exponent": 1.5e10,
  "negative_exp": 2.5e-4
}

No special values: NaN and Infinity are not valid JSON.

3. Boolean

Either true or false. Lowercase, no quotes.

{
  "isActive": true,
  "isDeleted": false
}

4. Null

Represents empty/nothing. Lowercase, no quotes.

{
  "middleName": null
}

5. Object

Key-value pairs wrapped in curly braces. Keys must be strings.

{
  "user": {
    "id": 123,
    "name": "Alice"
  }
}

Objects can nest infinitely.

6. Array

Ordered list wrapped in square brackets. Can contain any data type.

{
  "numbers": [1, 2, 3],
  "mixed": ["text", 42, true, null],
  "nested": [[1, 2], [3, 4]]
}

What JSON Does NOT Support

  • Functions: No code execution
  • Dates: Represented as strings (ISO 8601: "2026-02-14T21:00:00Z")
  • Undefined: Use null instead
  • Comments: Not allowed
  • Single quotes: Double quotes only
  • Trailing commas: Not allowed

Nested JSON Structures

Real-world JSON often contains deeply nested objects and arrays.

{
  "company": {
    "name": "TechCorp",
    "founded": 2010,
    "departments": [
      {
        "name": "Engineering",
        "employees": [
          {"name": "Alice", "role": "Developer"},
          {"name": "Bob", "role": "DevOps"}
        ]
      },
      {
        "name": "Marketing",
        "employees": [
          {"name": "Carol", "role": "Designer"}
        ]
      }
    ]
  }
}

Our JSON formatter helps visualize these nested structures with collapsible tree views.

Valid vs Invalid JSON

Let's spot the errors:

Example 1

{
  name: "Alice",
  "age": 30
}

Invalid: name is not quoted.

Example 2

{
  "name": "Alice",
  "age": 30,
}

Invalid: Trailing comma after 30.

Example 3

{
  "name": 'Alice'
}

Invalid: Single quotes around Alice.

Example 4

{
  "date": new Date()
}

Invalid: new Date() is JavaScript code, not a JSON value.

Example 5

{
  "value": NaN
}

Invalid: NaN is not a valid JSON value.

Use our JSON validator to check your JSON instantly.

Where JSON Is Used

1. Web APIs (REST APIs)

The overwhelming majority of REST APIs use JSON for request and response bodies.

GET https://api.example.com/users/123

Response:
{
  "id": 123,
  "name": "Alice",
  "email": "[email protected]"
}

2. Configuration Files

Modern tools use JSON for configuration: package.json (Node.js), tsconfig.json (TypeScript), VS Code settings, etc.

{
  "name": "my-app",
  "version": "1.0.0",
  "dependencies": {
    "express": "^4.18.0"
  }
}

3. Databases

NoSQL databases like MongoDB store documents as JSON (technically BSON). PostgreSQL and MySQL have native JSON column types.

4. Web Storage

Browsers' localStorage and sessionStorage store strings — JSON lets you save complex objects:

localStorage.setItem('user', JSON.stringify({name: "Alice"}));

5. Data Exchange

Any time systems need to communicate — microservices, webhooks, message queues — JSON is often the format of choice.

JSON vs JavaScript Objects

They look similar, but they're different:

Feature JSON JavaScript Object
Keys Must be quoted Can be unquoted
Strings Double quotes only Single or double
Trailing commas Not allowed Allowed
Comments Not allowed Allowed
Functions Not allowed Allowed
undefined Not allowed Allowed

Converting Between Them

JavaScript to JSON:

const obj = {name: "Alice", age: 30};
const json = JSON.stringify(obj);
// '{"name":"Alice","age":30}'

JSON to JavaScript:

const json = '{"name":"Alice","age":30}';
const obj = JSON.parse(json);
// {name: "Alice", age: 30}

Quick Tutorial: Reading and Writing JSON

Reading JSON (JavaScript)

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

// Access nested values
const json = '{"user": {"profile": {"name": "Bob"}}}';
const obj = JSON.parse(json);
console.log(obj.user.profile.name); // "Bob"

// Access array items
const arr = JSON.parse('[1, 2, 3]');
console.log(arr[0]); // 1

Writing JSON (JavaScript)

// Create JSON from object
const user = {
  name: "Alice",
  age: 30,
  hobbies: ["reading", "coding"]
};
const json = JSON.stringify(user);

// Pretty print with indentation
const prettyJson = JSON.stringify(user, null, 2);

Reading JSON (Python)

import json

# Parse JSON string
data = json.loads('{"name": "Alice"}')
print(data['name'])  # Alice

# Read from file
with open('data.json') as f:
    data = json.load(f)

Writing JSON (Python)

import json

data = {"name": "Alice", "age": 30}

# Convert to string
json_str = json.dumps(data)

# Write to file (pretty)
with open('output.json', 'w') as f:
    json.dump(data, f, indent=2)

Working with Our Tools

Format Messy JSON

Paste minified or poorly formatted JSON into our JSON formatter to get clean, indented output:

Before:

{"name":"Alice","age":30,"hobbies":["reading","coding"]}

After:

{
  "name": "Alice",
  "age": 30,
  "hobbies": [
    "reading",
    "coding"
  ]
}

Validate JSON

Not sure if your JSON is valid? Our JSON validator checks syntax and highlights exact error locations.


FAQ: JSON Questions

Is JSON the same as a JavaScript object?

No. JSON is a text-based data format derived from JavaScript object syntax. JavaScript objects are in-memory data structures with more flexibility (functions, unquoted keys, comments). JSON.parse() converts JSON text to objects; JSON.stringify() converts objects to JSON text.

Can JSON have comments?

No. Standard JSON does not support comments. If you need comments, consider JSONC (JSON with Comments, supported by VS Code) or YAML. Some parsers strip comments as a preprocessing step, but this isn't standard JSON.

What's the maximum size of a JSON file?

There's no specification limit. Practical limits depend on the parser and available memory. Most parsers handle files up to several gigabytes, but streaming parsers are better for very large datasets.

Is JSON better than XML?

For most modern use cases, yes. JSON is lighter, faster to parse, more readable, and has native support in JavaScript. XML has advantages in document markup and has stronger schema validation. See our full comparison: JSON vs XML.

Why do API responses use JSON instead of other formats?

JSON is lightweight (smaller payloads), easy to parse (native JavaScript support), human-readable, and universally supported. It's the de facto standard for REST APIs.


Format your JSON: JSON Formatter →
Validate your JSON: JSON Validator →


Need to convert JSON to other formats? Try our JSON to CSV and JSON to XML converters.

Format JSON Instantly

Beautify, minify, and validate JSON with syntax highlighting and error detection.

Open JSON Formatter