JSON Formatter
Format, validate, and explore JSON — instantly in your browser.
How to use the JSON Formatter
What is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. Introduced as part of JavaScript in the early 2000s and standardised as RFC 8259, JSON has become the de facto standard for REST API responses, configuration files, and data storage across virtually every programming language and platform.
Despite its name, JSON is language-agnostic. Python, Ruby, Go, Java, Swift, PHP, Rust — all have native or standard-library JSON parsers. The format's simplicity is its key strength: it has only six value types (string, number, boolean, null, object, and array), a predictable syntax, and no ambiguity about encoding when UTF-8 is used.
A JSON object is a collection of key-value pairs enclosed in curly braces. Keys must be strings (double-quoted), and values can be any of the six types. Arrays are ordered lists enclosed in square brackets. This recursive structure lets JSON represent arbitrarily complex hierarchical data in a compact, readable form.
The challenge JSON formatters solve is that parsers and APIs produce minified JSON — all whitespace stripped to minimize bytes transferred. Minified JSON is efficient for machines but nearly unreadable for humans. Formatting (or "pretty-printing") JSON adds consistent indentation and newlines, making the hierarchy immediately visible without changing the data in any way.
JSON syntax quick reference
| Type | Syntax | Notes |
|---|---|---|
| String | "hello world" | Double quotes only. Escape with \", \\, \n, \t |
| Number | 42 3.14 -7 1e10 | No octal/hex literals. No trailing decimal. |
| Boolean | true false | Lowercase only (not True or TRUE) |
| Null | null | Lowercase only. Represents intentional absence of value. |
| Object | {"key": "value"} | Keys must be double-quoted strings. No trailing comma. |
| Array | [1, "two", true] | Can mix types. No trailing comma after last item. |
| Nested | {"a": {"b": [1, 2]}} | Objects and arrays can nest to any depth. |
Examples
Example 1: Minified API response → formatted
Example 2: JSON with a syntax error
Common JSON mistakes
- Trailing commas — JSON does not allow a comma after the last item in an object or array. This is the single most common mistake, especially when editing by hand.
- Single quotes — All strings, including keys, must use double quotes. Single quotes are valid JavaScript but not valid JSON.
- Unquoted keys — In JavaScript object literals you can write
{name: "value"}, but in JSON every key must be a double-quoted string:{"name": "value"}. - Comments — Standard JSON does not support comments (
// commentor/* comment */). If you need comments in config files, consider YAML, TOML, or the non-standard JSONC format understood by some tools. - Undefined and NaN — The JavaScript values
undefined,NaN, andInfinityare not valid JSON.JSON.stringify()convertsundefinedvalues tonullin arrays and omits them in objects.
Frequently asked questions
JSON formatting (also called pretty-printing) adds consistent indentation and line breaks to minified or unformatted JSON, making it human-readable without changing the data. The tool parses your JSON and then re-serializes it with the chosen indent size.
Yes. The JSON Formatter runs 100% in your browser using JavaScript. No data is ever sent to any server. You can verify this by opening your browser's DevTools Network tab and observing that no requests are made while you type or format. Your data stays on your machine.
The most common causes are: trailing commas after the last item in an object or array, single quotes instead of double quotes around strings or keys, unquoted keys (valid in JS but not JSON), missing commas between items, and comments (which JSON does not support). The error message includes the exact character position to help you pinpoint the issue.
JSONC (JSON with Comments) is a non-standard superset of JSON used by tools like VS Code's settings.json. It allows // single-line and /* multi-line */ comments. Standard JSON parsers — including this formatter — will reject JSONC files containing comments. Use a dedicated JSONC parser or strip comments before processing.
Yes, up to several megabytes without issue in modern browsers. Very large files (50 MB+) may slow down the browser tab because the entire file must be held in memory and rendered as text. For files that large, a local tool like jq (a command-line JSON processor) or a code editor with a JSON plugin is a better choice.
Two spaces is the most common convention for JSON files in JavaScript and Node.js projects. Four spaces is common in Python and Java communities. The choice is purely a style preference — JSON itself specifies no indentation. If you're contributing to an existing project, match whatever the project already uses.