JSON Formatter
Format and beautify JSON data
JSON (JavaScript Object Notation) is the most common data interchange format on the web. It's human-readable, language-independent, and natively supported by every modern programming language.
What is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. Despite its name, JSON is language-independent — it is natively supported by JavaScript, Python, Java, Go, Rust, C#, Ruby, PHP, and virtually every other modern programming language.
JSON was derived from JavaScript object literal syntax, but it is strictly a data format — not a programming language. It was formalized by Douglas Crockford in the early 2000s as a simpler alternative to XML for transmitting structured data between a server and a web application. Today, JSON is the dominant format for REST APIs, configuration files, and data storage in document databases like MongoDB and CouchDB.
JSON Data Types
JSON supports exactly six data types organized into two structures:
Primitive Types
| Type | Description | Example |
|---|---|---|
| String | Unicode text enclosed in double quotes | "hello world" |
| Number | Integer or floating-point (no hex, no NaN, no Infinity) | 42, 3.14, -7 |
| Boolean | True or false (lowercase only) | true, false |
| Null | Explicit absence of value (lowercase only) | null |
Structural Types
| Type | Description | Example |
|---|---|---|
| Object | Unordered collection of key-value pairs | {"key": "value"} |
| Array | Ordered list of values | [1, 2, 3] |
Objects and arrays can be nested to any depth, and values within them can be any of the six JSON types. This simple recursive structure is what makes JSON so versatile.
Common JSON Errors
JSON’s simplicity also means its parser is strict. Here are the most frequent mistakes:
| Error | Wrong | Correct |
|---|---|---|
| Single-quoted keys | {'name': 'Alice'} | {"name": "Alice"} |
| Unquoted keys | {name: "Alice"} | {"name": "Alice"} |
| Trailing comma | {"a": 1, "b": 2,} | {"a": 1, "b": 2} |
| Single-quoted strings | {"name": 'Alice'} | {"name": "Alice"} |
| Comments | {"a": 1} // comment | {"a": 1} |
| Undefined | {"a": undefined} | {"a": null} |
JSON does not support comments, trailing commas, single quotes, or undefined. These are all valid in JavaScript but forbidden in JSON. If you need comments in configuration files, consider JSON5 or JSONC (JSON with Comments), which extend the format with these conveniences.
JSON vs XML vs YAML
| Feature | JSON | XML | YAML |
|---|---|---|---|
| Readability | Good | Verbose | Excellent |
| Data types | 6 built-in | Text only (attributes + elements) | Rich (dates, binary, etc.) |
| Comments | Not supported | Supported (<!-- -->) | Supported (#) |
| Schema validation | JSON Schema | XSD, DTD, RelaxNG | JSON Schema (reused) |
| File size | Compact | Large (tags repeat) | Most compact |
| Parsing speed | Fast | Moderate | Slower |
| Primary use | APIs, configs | Enterprise, SOAP, documents | Configs, DevOps |
JSON strikes a balance between human readability and machine efficiency. XML is more expressive (with attributes, namespaces, and mixed content) but significantly more verbose. YAML is the most human-friendly but its indentation-based syntax can be error-prone, and its parser is more complex.
For web APIs, JSON has decisively won. For configuration files, YAML is popular in the DevOps ecosystem (Kubernetes, Docker Compose, GitHub Actions). XML remains dominant in enterprise systems, SOAP services, and document formats.
Common Use Cases
- REST APIs: JSON is the default request and response format for virtually all modern REST APIs
- Configuration files:
package.json,tsconfig.json,.eslintrc.json, and many other tools use JSON for configuration - Document databases: MongoDB, CouchDB, and DynamoDB store documents as JSON (or BSON)
- Data exchange: Microservices communicate using JSON over HTTP, WebSocket, or message queues
- Local storage: Browsers serialize JavaScript objects to JSON for
localStorageandsessionStorage - Logging: Structured logging systems (ELK stack, Datadog) consume JSON-formatted log entries for parsing and indexing
Try These Examples
A valid JSON object containing a string, number, array of strings, and a nested object. All keys are double-quoted, and values use the correct JSON data types.
{"name": "Alice", "age": 30, "roles": ["admin", "editor"], "address": {"city": "Paris", "zip": "75001"}} Invalid because JSON does not allow trailing commas after the last property. This is the most common JSON syntax error — JavaScript allows it, but JSON does not.
{"name": "Alice", "age": 30,}