Developer Tools
Free JSON Formatter & Validator Online
Format, beautify, minify and validate JSON data online.
What is JSON?
JSON (JavaScript Object Notation) is a lightweight text format for storing and transmitting structured data. It is the standard data format for REST APIs, configuration files, and web application data exchange. JSON is language-independent — every major programming language can parse and serialize it.
Serialization is the process of converting a data structure into JSON text (e.g. JSON.stringify(obj)). Deserialization is the reverse — parsing JSON text back into a usable object (e.g. JSON.parse(str)). Both operations use the same JSON format defined in RFC 8259.
JSON uses two structures: objects (key-value pairs in curly braces) and arrays (ordered lists in square brackets). Values can be strings, numbers, booleans, null, objects, or arrays — fully nestable.
How to use the JSON formatter
- 1Paste your JSON
Paste any JSON string into the input field — minified, prettified, or broken. The formatter handles all formats.
- 2Choose a mode
Prettify adds indentation and line breaks for human readability. Minify removes all whitespace for production use. Validate checks syntax and highlights errors without transforming.
- 3Set indentation
Choose 2-space or 4-space indentation. JavaScript and Node.js projects typically use 2 spaces. Python and Java projects often use 4.
- 4Copy the result
Click Copy to grab the formatted output. The entire process runs locally in your browser — your API keys and data never leave your device.
Common JSON syntax errors
JSON has strict syntax rules. These are the errors developers encounter most often:
{"key": "value",}Remove the comma after the last property. JSON does not allow trailing commas, unlike JavaScript.
{"key": 'value'}Use double quotes for all strings and property names. Single quotes are not valid JSON.
{key: "value"}All object keys must be quoted: {"key": "value"}.
{"value": undefined}JSON has no undefined or NaN types. Use null for missing values.
{"key": "value" // note}JSON does not support comments. Remove them or use a format like JSONC for config files.
Prettify vs Minify — when to use each
- Debugging API responses
- Reading config files
- Code reviews and documentation
- Exploring unfamiliar data structures
- Sending data in API requests
- Storing in databases
- Reducing payload size for production
- Embedding JSON in HTML attributes
JSON data types — complete reference
JSON supports exactly six value types. Understanding them is essential for writing valid JSON and debugging parse errors.
| Type | Example | Notes |
|---|---|---|
| String | "Hello, world!" | Must use double quotes. Escape special chars: \" \n \t \\ |
| Number | 42 or 3.14 or -7 | No integer/float distinction. No NaN or Infinity (invalid in JSON) |
| Boolean | true or false | Lowercase only. "True" or "TRUE" are invalid |
| Null | null | Represents an absent or unknown value. undefined does not exist in JSON |
| Object | {"key": "value"} | Unordered key-value pairs. Keys must be double-quoted strings |
| Array | [1, "two", true, null] | Ordered list. Can mix types. Can be nested inside objects |
Working with JSON in JavaScript
Two built-in functions handle all JSON operations in JavaScript. Both are synchronous and available in every browser and Node.js environment.
const data = JSON.parse('{"name": "Alice", "age": 30}');
console.log(data.name); // "Alice"Throws SyntaxError if the string is not valid JSON. Always wrap in try/catch when parsing user input or API responses.
const obj = { name: 'Alice', scores: [95, 87, 92] };
const json = JSON.stringify(obj, null, 2); // null = no replacer, 2 = indentThe second argument filters keys (pass null to keep all). The third argument sets indentation — use 2 for readability, omit for minified output.
const res = await fetch('https://api.example.com/data');
const data = await res.json(); // parses JSON automaticallyres.json() is shorthand for res.text() → JSON.parse(). It throws if the response body is not valid JSON.
JSON vs XML vs YAML vs TOML
JSON is the dominant format for APIs and web applications, but other formats serve different purposes. Here's when each makes sense:
JSON Schema — validating structure and types
JSON has no built-in type enforcement — any valid JSON can contain any structure. JSON Schema is a separate vocabulary (itself written in JSON) that describes the expected structure of a JSON document. It is used for API documentation, form validation, config file validation, and code generation.
A JSON Schema document specifies the type of each property, whether properties are required, constraints like minLength, minimum, and pattern, and the structure of nested objects and arrays. Validators like Ajv (JavaScript) and jsonschema (Python) use the schema to validate payloads at runtime — rejecting malformed data before it reaches your business logic.
OpenAPI (formerly Swagger) uses JSON Schema as its type system for API definitions. TypeScript tools like json-schema-to-typescript generate TypeScript interfaces directly from a JSON Schema, keeping your API types and validation rules in sync automatically.
JSON in the real world — APIs, config files, databases
JSON is everywhere in modern software. Understanding the common patterns helps you work with it more confidently across different contexts:
The dominant format for web API payloads. Content-Type: application/json signals JSON encoding. Most HTTP client libraries (Axios, Fetch API, requests, Guzzle) parse JSON responses automatically. Pagination typically uses a wrapper object with "data", "meta", and "links" keys (JSON:API spec) or a flat response with "items" and "nextCursor".
Node.js project configuration and dependency manifest. Uses JSON5-extended rules in some tooling but must be strictly valid JSON. The scripts object defines npm run commands; dependencies and devDependencies use semver ranges. Processed by the npm CLI — never needs to be parsed manually by your code.
TypeScript compiler configuration. Unusually, this file supports JavaScript-style comments (// and /* */) and trailing commas despite using the .json extension. TypeScript's parser handles these JSON5 extensions internally. This is why linters sometimes complain about tsconfig.json being "invalid JSON".
Browser storage only holds string values. Storing objects requires JSON.stringify() on write and JSON.parse() on read. A common bug is forgetting to parse on retrieval — comparing a stored boolean with true will always fail if the value was stored as the string "true". Always pair storage and retrieval with the same serialization approach.
PostgreSQL natively stores and indexes JSON in JSONB (binary JSON) columns. You can query nested properties with -> and ->> operators, index specific keys with GIN indexes, and update individual paths. JSONB is preferred over the older JSON type because it stores data in binary form (faster queries) and deduplicates object keys.
Real-time protocols commonly use JSON-encoded messages. WebSocket frames carry raw bytes — JSON.stringify/parse handles encoding. Server-Sent Events use a "data: {...}\n\n" format where the data field contains a JSON string. For high-frequency messages (gaming, financial data), consider MessagePack or Protocol Buffers as more compact binary alternatives.
FAQ
Common questions
What is JSON?
JSON (JavaScript Object Notation) is a lightweight data format used to exchange data between servers and web applications. It's human-readable and language-independent, making it the standard for REST APIs and configuration files.
What does prettify do?
Prettify (also called "beautify") adds consistent indentation and line breaks to make JSON easy to read. Choose 2-space or 4-space indentation based on your style guide.
What does minify do?
Minify removes all whitespace, indentation, and newlines to produce the most compact JSON string. This reduces file size for network transfer — useful before sending JSON in API responses or storing in databases.
Why is my JSON invalid?
Common issues: trailing commas after the last property (not allowed in JSON), single quotes instead of double quotes, unquoted property keys, or undefined/NaN values (not valid JSON primitives).
Is my data safe?
Yes. All processing happens entirely in your browser using JavaScript's built-in JSON.parse() and JSON.stringify(). Nothing is sent to any server.
Can JSON have comments?
No — standard JSON does not support comments. This is intentional: JSON is a data interchange format, not a config format. If you need comments in config files, use JSONC (JSON with Comments, used by tsconfig.json and VS Code settings), JSON5, YAML, or TOML instead. Attempting to parse JSON with comments using JSON.parse() will throw a SyntaxError.
How should I handle dates in JSON?
JSON has no native date type. The convention is to use ISO 8601 strings: "2024-01-15T10:30:00Z". When parsing, convert the string to a Date object manually: new Date(obj.createdAt). Never store dates as Unix timestamps in JSON if human readability matters — ISO strings are self-documenting and timezone-aware with the Z suffix.
What is JSON Lines (NDJSON) and when should I use it?
JSON Lines (also called NDJSON — Newline-Delimited JSON) stores one JSON object per line with no wrapping array. This format is ideal for log files, data streams, and large datasets because you can read and process line-by-line without loading the entire file into memory. Tools like jq, Spark, and BigQuery natively support NDJSON.
More in Developer Tools