JSON Formatter / Validator

Format, validate, inspect, sort and minify JSON online. Paste raw, compact or broken JSON to pretty-print it with 2 spaces, 4 spaces, or tab indentation, switch between highlighted text and collapsible tree view, detect duplicate keys, view structure stats, sort object keys alphabetically, download the result, or compact JSON for production use. Everything runs locally in your browser.

Input
0 chars · 0 bytes
Try:
Result
✓ Validates JSON syntax and reports errors ✓ Pretty-prints and minifies in the browser ✓ Client-side processing only
Examples
Format object
Input {"name":"Alice","age":30,"active":true}
Output { "name": "Alice", "age": 30, "active": true }

A flat JSON object is expanded with 2-space indentation for easy reading.

Format array
Input [{"id":1,"role":"admin"},{"id":2,"role":"user"}]
Output [ { "id": 1, "role": "admin" }, { "id": 2, "role": "user" } ]

A JSON array of objects is formatted with nested indentation.

Minify
Input { "key": "value", "count": 42 }
Output {"key":"value","count":42}

Formatted JSON is compacted into a single line by removing all whitespace.

Format nested API response
Input {"status":"ok","data":{"items":[{"id":101,"tags":["json","api"]},{"id":102,"tags":[]}],"next":null}}
Output { "status": "ok", "data": { "items": [ { "id": 101, "tags": [ "json", "api" ] }, { "id": 102, "tags": [] } ], "next": null } }

A nested API-style payload is pretty-printed so objects, arrays and null values are easier to inspect.

What is JSON formatting?

JSON (JavaScript Object Notation) is a lightweight data-interchange format used by APIs, configuration files, logs, web apps, build tools and data exports. It is easy for machines to parse, but minified JSON or deeply nested API responses can be difficult for people to read.

This online JSON formatter, also called a JSON beautifier or pretty printer, parses the raw JSON text, validates it for syntax correctness, and serialises it back with consistent indentation. You can choose 2 spaces, 4 spaces, or tab indentation, then inspect the result as highlighted text or as a collapsible tree.

Format vs minify JSON

Formatting (the Format tab) makes JSON human-readable by expanding objects and arrays onto separate lines and adding indentation. Use it when debugging API responses, reviewing webhook payloads, checking frontend state, comparing configuration files, or understanding nested data before copying it into code.

Minification (the Minify tab) removes unnecessary whitespace and line breaks, producing a compact one-line JSON string. Use it when embedding JSON in source code, storing payloads in environment variables, sending test requests, or reducing transfer size. The values remain the same; only the whitespace changes.

JSON data types

JSON supports exactly six value types:

  • String — a sequence of Unicode characters in double quotes. Special characters must be escaped with a backslash: \", \, \/, \n, \r, \t, \uXXXX. Example: "Hello, world!"
  • Number — an integer or floating-point value. Leading zeros, Infinity, and NaN are not allowed. Example: 42, -3.14, 1.5e10
  • Boolean — exactly true or false (lowercase only).
  • Null — exactly null (lowercase only), representing the absence of a value.
  • Object — an unordered collection of key-value pairs wrapped in {}. Keys must be strings. Example: {"name": "Alice", "age": 30}
  • Array — an ordered list of values wrapped in []. Values may be of any JSON type and may be mixed. Example: [1, "two", true, null]
JSON syntax rules

A few rules that frequently cause JSON validation errors:

  • No trailing commas. {"a": 1,} and [1, 2,] are invalid. The last element in an object or array must not be followed by a comma.
  • No comments. JSON does not support // line or /* block */ comments. Strip them before parsing.
  • Double quotes only. String keys and values must use "double quotes". Single quotes (') and backticks are not allowed.
  • No undefined or functions. Only the six types listed above are valid. JavaScript values like undefined, NaN, Infinity, and functions cannot be represented in JSON.
  • Duplicate object keys are risky. JSON parsers usually keep the last value and silently discard earlier values. This tool warns about duplicate keys so you can fix ambiguous payloads before they reach an API or application.
  • Top-level value can be any type. A valid JSON document may be a string, number, boolean, null, object, or array — not just an object.
JSON validation and error details

The validator runs before any output is produced. If the input is not valid JSON, the tool shows the parser error and, when the browser provides enough information, highlights the approximate line and column in the source text. This is useful for quickly finding missing commas, invalid quotes, unescaped control characters, truncated arrays, or malformed numbers.

Because the formatter uses the browser's native JSON parser, it follows strict JSON syntax rather than JavaScript object literal syntax. A value such as {name: 'Alice'} may look familiar in JavaScript, but it is not valid JSON because the key and string value must use double quotes.

Inspect JSON structure

After a successful format operation, the output includes a highlighted text view and a collapsible tree view. The tree view is helpful for exploring deeply nested objects and arrays without losing your place, while the text view is better for copying formatted JSON into an editor, issue tracker, documentation page, or API client.

The tool also calculates structure statistics: number of objects, arrays, keys, maximum depth, characters and bytes. These quick metrics help estimate payload size, spot unexpectedly deep nesting, and understand whether a response is mostly object metadata, list data, or a mixed structure.

Sort keys and download JSON

The Sort Keys action alphabetically sorts object keys recursively while keeping array order unchanged. This can make configuration files easier to scan, reduce visual noise in code reviews, and make two JSON documents easier to compare after formatting.

The Download action saves the current JSON result as a file, so you can keep a cleaned payload, share a reproducible example, or archive a minified configuration without copying from the browser manually.

FAQ

Two spaces is the most common convention in JavaScript and web projects. Four spaces is standard in many other languages and is easier to read in deeply nested structures. Tab indentation preserves the original formatting intent while allowing each viewer's editor to display the preferred width. Choose the one that matches your project's coding style.

Yes. The formatter first parses the input using the browser's built-in JSON parser. If the input is not valid JSON, an error message is shown immediately with a description of the problem. When the browser exposes a position, the tool also shows the line and column and selects the approximate error location in the input.

No. All processing happens entirely in your browser using JavaScript. Your JSON is never transmitted to any server. This makes the tool safe to use with sensitive configuration files, API keys, or private data structures.

No. Minification parses the JSON and serialises the same data without unnecessary spaces or line breaks. Strings, numbers, booleans, null values, arrays and objects keep their values. The visible difference is that the output becomes compact and usually fits on a single line.

Yes. In Format mode, use the Sort Keys button to sort object keys alphabetically at every nesting level. Arrays keep their original order because array position is meaningful data. Sorting is useful for configuration files, deterministic examples and easier visual comparison.

The tree view renders objects and arrays as collapsible nodes, with keys, indexes and primitive values highlighted by type. It is designed for exploring nested payloads without scrolling through a long block of text.

Yes. The tool scans the raw JSON and warns when the same key appears more than once inside the same object. Standard JSON parsing usually keeps the last duplicate value, which can hide mistakes in API payloads or configuration files.

Yes. After formatting or minifying a valid JSON document, use the Download button to save the current output as a JSON file. This is convenient when cleaning up exported data, API examples or configuration snippets.

A valid JSON document may start with an object, array, string, number, boolean or null. Many APIs use objects or arrays, but the JSON standard also allows top-level primitive values such as "hello", 42, true or null.
Related tools

Binary Converter Online

Convert text into 8-bit binary groups and decode binary bytes back into readable text.

ASCII Converter

Convert ASCII characters and numeric codes for protocol and parser workflows.

JWT Decoder Online

Decode JWT tokens in-browser and inspect header, payload, claims, and expiration data.