JSON Formatter

Format and beautify JSON data

1
Understanding JSON Format
TL;DR

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

TypeDescriptionExample
StringUnicode text enclosed in double quotes"hello world"
NumberInteger or floating-point (no hex, no NaN, no Infinity)42, 3.14, -7
BooleanTrue or false (lowercase only)true, false
NullExplicit absence of value (lowercase only)null

Structural Types

TypeDescriptionExample
ObjectUnordered collection of key-value pairs{"key": "value"}
ArrayOrdered 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:

ErrorWrongCorrect
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

FeatureJSONXMLYAML
ReadabilityGoodVerboseExcellent
Data types6 built-inText only (attributes + elements)Rich (dates, binary, etc.)
CommentsNot supportedSupported (<!-- -->)Supported (#)
Schema validationJSON SchemaXSD, DTD, RelaxNGJSON Schema (reused)
File sizeCompactLarge (tags repeat)Most compact
Parsing speedFastModerateSlower
Primary useAPIs, configsEnterprise, SOAP, documentsConfigs, 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 localStorage and sessionStorage
  • Logging: Structured logging systems (ELK stack, Datadog) consume JSON-formatted log entries for parsing and indexing

Try These Examples

Valid JSON Object with Nested Array Valid

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 JSON — Trailing Comma Invalid

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,}