Processing JSON...
Paste JSON above and click Format, Minify, or Validate.
What Is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format defined in ECMA-404 and standardised as an internet protocol in RFC 8259. It is the dominant format for REST APIs, configuration files, and data storage because it is human-readable and trivially parsed by every programming language.
JSON supports exactly six value types:
| Type | Example | Notes |
|---|---|---|
| string | "hello" | Always double-quoted |
| number | 42 · 3.14 · -7 | No NaN or Infinity |
| boolean | true · false | Lowercase only |
| null | null | Lowercase only |
| object | { } | Unordered key-value pairs |
| array | [ ] | Ordered list of values |
How to Format JSON
Formatting (or "pretty-printing") JSON adds indentation and line breaks so each key-value pair sits on its own line and nested structures are visually indented. This makes large payloads readable and makes version-control diffs useful.
2-space indentation is the most common choice: it balances readability with horizontal space. 4-space indentation is preferred in Python-heavy teams. Tab indentation lets each developer choose their display width in their editor.
This tool's output always has alphabetically sorted keys. Sorted keys make two JSON objects with the same data identical as text — important for reproducible builds, snapshot testing, and clean git diffs.
How to Validate JSON — Common Errors
Validation checks that a JSON string conforms to the ECMA-404 grammar. The most frequent errors are:
| Error | Example | Fix |
|---|---|---|
| Trailing comma | {"a":1,} | Remove the last comma |
| Single-quoted strings | {'key':'val'} | Use double quotes |
| Unquoted keys | {key: "val"} | Quote all keys: {"key":"val"} |
| Comments | // not valid | JSON has no comment syntax |
| Missing bracket | {"a":[1,2} | Close every [ ] and { } |
| Undefined / NaN | {"x":NaN} | Use null or a string instead |
This validator uses Go's encoding/json package, which reports the exact byte offset of every syntax error. The tool converts that offset into a human-readable line and column number.
JSON Minification — When and Why
Minified JSON removes all whitespace that is not part of a string value: spaces, tabs, and newlines. The result is a single long line that is 30–60% smaller than pretty-printed output for typical API responses.
Minification matters most when JSON is sent over the network — REST API responses, WebSocket messages, and localStorage payloads. A 10 KB formatted config file might minify to 6 KB, saving bandwidth on every page load.
When not to minify: configuration files checked into version control should stay formatted and sorted so git diffs remain readable. Use minification only for built or deployed artefacts.
Frequently Asked Questions
What is the difference between JSON and a JavaScript object?
A JavaScript object is a runtime value in memory. JSON is a text representation — a string. JSON is a strict subset of JavaScript object literal syntax: all keys must be double-quoted, functions and undefined are not allowed, and trailing commas are forbidden. You can use JSON.parse() to convert a JSON string into a live JavaScript object.
Can JSON have comments?
No. The JSON specification explicitly excludes comments. This was a deliberate design choice by Douglas Crockford to prevent comments from being used as parsing directives. If you need comments in a config file, consider JSONC (JSON with Comments) or YAML — but note that these are not valid JSON and require special parsers.
What causes an "unexpected token" error?
The parser reached a character it did not expect at that position. Common causes: a trailing comma after the last element, a single-quoted string, an unquoted key, a JavaScript keyword like undefined, or a missing closing bracket. The line and column number in the error message points to where the parser gave up — the actual mistake is often one token before that position.
Is JSON case-sensitive?
Yes, entirely. The keywords true, false, and null must be lowercase. String values and object keys are compared as-is, so "Name" and "name" are different keys.
Why does formatting make JSON larger?
Pretty-printed JSON adds spaces after colons and commas plus newlines and indentation characters for every level of nesting. A deeply nested document can grow by 50–100% compared to its minified form. This is why production APIs send minified JSON but developers work with formatted JSON.
Why are JSON keys sorted in the output?
Go's encoding/json marshals map[string]interface{} with keys in alphabetical order. Sorted keys make JSON documents deterministic — the same data always produces the same text. This is valuable for snapshot tests, reproducible builds, and clean version-control history where only meaningful changes appear in diffs.
Further Reading
Authoritative references for the JSON specification, language integration, and the Go library that powers this tool.
ECMA-404 — The JSON Data Interchange Standard
The official specification from Ecma International. The authoritative grammar for valid JSON syntax.
IETF RFC 8259 — JSON as an Internet Standard
The IETF standardisation of JSON for internet protocols, including interoperability requirements and character encoding rules.
MDN Web Docs — JSON.parse()
Complete browser reference for parsing JSON in JavaScript, including reviver functions, error handling, and security considerations.
Go Standard Library — encoding/json
Official docs for the package that powers this tool's formatting, minification, and validation backend.