JSON stands for JavaScript Object Notation. It is a lightweight, text-based format for storing and exchanging data. Despite its name, JSON is language-independent and nearly every modern programming language can parse and generate it.
Why JSON Matters
If you have ever called a web API, read a config file, or sent data between a frontend and backend, you have used JSON. It is the de facto standard for data interchange on the web. REST APIs return JSON. GraphQL wraps responses in JSON. Even databases like MongoDB store documents in a JSON-like format called BSON.
The reason JSON won is simple: it is easy for humans to read and easy for machines to parse. Unlike XML, JSON has minimal overhead. No closing tags, no schema declarations — just keys, values, and structure.
JSON Data Types
JSON supports exactly six data types:
- **String** — text enclosed in double quotes: "hello"
- **Number** — integers and floats: 42, 3.14
- **Boolean** — true or false
- **Null** — represents absence of value
- **Object** — unordered key-value pairs: {"name": "Alice"}
- **Array** — ordered list of values: [1, 2, 3]
Every JSON value is one of these six types. That is the entire specification.
JSON Syntax Rules
JSON has strict syntax rules that you must follow:
- Keys must be double-quoted strings
- String values must use double quotes, not single quotes
- No trailing commas after the last item in an object or array
- Comments are not allowed
- The top-level value must be an object or array
Here is a valid JSON object:
{"name": "JSONClean", "version": 1, "features": ["format", "validate", "diff"], "free": true}
Notice every key is quoted. Notice there is no trailing comma after "true". These rules catch people off guard when they first write JSON by hand.
JSON vs JavaScript Objects
JSON looks like JavaScript object literal syntax, but they are not the same thing:
- JSON requires double quotes around all keys and string values
- JavaScript allows unquoted keys and single-quoted strings
- JSON has no concept of undefined, functions, or Date objects
- JSON is purely a data format, not executable code
In JavaScript you convert between them with JSON.parse() and JSON.stringify(). Every other language has equivalent library functions.
Common Mistakes
These are the errors people make most often when writing JSON:
- Using single quotes instead of double quotes
- Adding a trailing comma after the last property
- Forgetting to quote a key
- Including a comment with // or /* */
- Using undefined or NaN as values
If your JSON is malformed, parsers will reject it entirely. JSON does not do partial parsing — it either works or it fails. Use a validator to catch these issues before they reach production.
Working with JSON in Practice
Here is how you parse and generate JSON in popular languages:
In JavaScript:
const data = JSON.parse('{"key": "value"}'); const json = JSON.stringify(data, null, 2);
In Python:
import json data = json.loads('{"key": "value"}') text = json.dumps(data, indent=2)
In Go:
import "encoding/json" err := json.Unmarshal([]byte(str), &data) bytes, err := json.MarshalIndent(data, "", " ")
The pattern is the same everywhere: parse a string into native data structures, manipulate them, then serialize back to a string.
When to Use JSON
JSON is the right choice when you need to:
- Send data between a client and server over HTTP
- Store configuration files
- Serialize data for caching or message queues
- Exchange data between services written in different languages
JSON is not the best choice for:
- Very large datasets where binary formats like Protocol Buffers are more efficient
- Documents that need comments (use YAML instead)
- Highly structured data that benefits from a schema (consider Avro or Thrift)
The Bottom Line
JSON is simple, universal, and here to stay. Understanding its syntax, data types, and common pitfalls is foundational knowledge for any developer working on the modern web. If you are working with JSON and need to format, validate, or transform it, try our free JSON Formatter to clean up your data instantly.