Guide

How to Format and Validate JSON Online

Pretty-print messy JSON, validate syntax, and minify JSON for production. A complete guide for developers using browser-based tools.

By Sorawi Tools Team · Published July 1, 2026

What JSON Is and Why Formatting Matters

JSON (JavaScript Object Notation) is the de facto data interchange format for modern applications, formally defined by RFC 8259 and the ECMA-404 standard. It represents structured data as objects wrapped in braces with key-value pairs, arrays wrapped in brackets, and strings wrapped in double quotes. Because JSON is plain text, it is readable in principle — but it rarely is in practice. APIs compress responses to save bandwidth, loggers emit single-line objects, and configuration exports arrive minified with every byte of whitespace removed. Formatting, also called pretty-printing, adds indentation and line breaks so the structure becomes visible at a glance. The difference is dramatic: a minified API response that is one long, opaque line becomes a nested tree you can scan, understand, and debug in seconds. When you can see the nesting, you can find the field you need, notice that a value is missing, and tell whether an item is a single object or a list of them. Formatting is the first tool in any data inspection workflow, and it doubles as a free syntax check, because a formatter must parse your input before it can lay it out. That is why the first thing any developer does with a suspicious payload is paste it into a formatter: a clean, indented output means the data is structurally valid, and an error means the bug is on your side of the request.

The Exact Rules of Valid JSON

JSON has a small but unforgiving grammar, and knowing the rules is what turns a formatter error message into a quick fix. Keys must be double-quoted strings. String values must use double quotes, never single quotes. Every object must use braces, every array must use brackets, and pairs are separated by colons while members are separated by commas. The six legal value types are objects, arrays, strings, numbers, the boolean literals true and false, and null. Numbers can be integers or decimals, optionally in scientific notation such as 1.5e10, but never NaN or Infinity, and never hexadecimal or leading-zero forms like 01. Strings support escape sequences for quotes, backslashes, newlines, and Unicode, so a string containing a quote must escape it with a backslash. There is no concept of comments, trailing commas, or unquoted identifiers — the features that make JavaScript object literals forgiving are exactly what JSON rejects. Whitespace between tokens is permitted, which is why a formatter can restructure the layout without changing the data: indentation, newlines, and spaces are purely cosmetic to a JSON parser. A file that violates any of these rules is not JSON, and any conforming parser will reject it. Keep a mental checklist for the failure cases: comments, single quotes, trailing commas, and unquoted keys cover the vast majority of invalid files. When a formatter points at a specific line and character, the rule above tells you what to look for at that spot, and the fix is usually a single character.

When You Will Reach for a JSON Formatter

The most common trigger is debugging an API response: you paste a response body or a request payload into a formatter to see its real structure, and the shape of the data becomes obvious. Configuration files, environment exports, and database dumps are the other big sources of messy JSON. Testers use formatters to build readable fixtures and to verify that an endpoint returned the expected keys, because a formatted document reveals the shape of the data at a glance — you can see at once whether a field is missing, nested one level deeper than expected, or present but null. Anyone who works with logs benefits too, since log lines are frequently JSON objects on a single line, and formatting a batch of them exposes the common fields across entries and makes anomalies visible. Beyond debugging, the formatter is a working tool in every stage of building with JSON. When you are about to paste JSON into code, an editor, a schema validator, or a bug report, running it through a formatter first surfaces syntax errors before they cost you a failed request or a broken build. When you receive JSON from a colleague, an import, or a generator, formatting it is how you read it. And when you need to send compact JSON over a slow connection or store it in a field with a size limit, the same tool minifies it for you. One tool covers the whole lifecycle — inspect, validate, reformat, minify — so there is no reason to hand-format anything or to guess whether a payload is valid.

How to Format and Validate JSON Online

The JSON Formatter parses your input locally in the browser, so nothing is uploaded and even confidential API payloads stay on your machine. This matters for production data: pasting a real response into a third-party site can leak tokens, customer data, or internal fields that should never leave your network. It validates the syntax as it formats, which means a successful format is also proof that your JSON is valid. The tool gives you the full workflow in one place — format, validate, and minify — with an error message that points at the exact line when something is wrong.

  1. 1Open the JSON Formatter tool in your browser
  2. 2Paste your JSON into the input area, or drop a .json file onto the page
  3. 3Click Format to pretty-print with clean indentation
  4. 4Check the validation result — a formatted output means the syntax is valid
  5. 5Copy the formatted result, or fix any reported error and reformat
  6. 6Use Minify when you need a compact single-line version for storage or transfer

Formatting vs Minifying

Formatting and minifying are the same operation in reverse. Formatting inserts indentation, newlines, and spacing to maximize readability; minifying removes every non-essential character to minimize size. The two most common indent styles are two spaces and four spaces, plus the occasional tab, and a good formatter lets you switch between them to match your project's convention, because a file that switches indent styles mid-way is a readability headache. The size difference is not trivial: whitespace is the bulk of a formatted file, so minifying a large API payload can cut its byte size substantially before it is sent over the wire or stored in a database column. The rule of thumb is simple. Format anything a human will read, and minify anything a machine will consume — then use the same tool to go back and forth without ever hand-editing the layout. A useful habit is keeping both versions in a scratch file or a code comment: the formatted copy for review and the minified copy for the exact bytes you sent or stored. That pairing is especially valuable when you are comparing two API responses, because diffing the formatted versions shows semantic changes, while diffing the minified versions shows you the exact byte-level difference. The formatter keeps the two representations consistent by construction, so you never have to worry that your formatted view is out of sync with what is actually transmitted.

Common JSON Mistakes and How to Spot Them

Trailing commas are the single most common JSON error: a comma after the last member of an object or array is legal in JavaScript but illegal in JSON, and it trips up people coming from that language. Single-quoted strings and unquoted keys come next, both habits carried over from other languages or from loosely typed config systems. Comments are a frequent surprise, because many people assume a JSON file accepts the same comments as their YAML or JS config files — it does not, and comments are a top reason parsers fail on otherwise well-formed data. Duplicate keys are subtler: the standard says the last value wins, but parsers differ in how strictly they enforce or flag the situation, so a payload with two id keys behaves unpredictably depending on which parser reads it. Numbers with leading zeros, hexadecimal literals, or undefined values also fail validation, as does unescaped control data or a JSON string that was truncated mid-way by a buggy log truncator. The most confusing errors are often the smallest: a missing closing brace at the end of a five-thousand-line payload, or a semicolon left over from a copy-paste. A good formatter highlights the exact line and character of the error, which turns the fix into a single edit rather than a hunt. When you see an error, read the line it points at and look backward for the last structural character, because the reported position is often where the parser realized something was missing, not where the problem actually began.

What to Do After Your JSON Is Clean

Once your JSON validates, the real work begins. Compare the formatted output against what the consuming application expects, and look for missing, renamed, or unexpected keys before the request goes out. For large structures, diffing against a previous version makes changes obvious, and the formatted layout is what makes the diff readable in the first place. If you are working with data that is not JSON, remember the neighboring formats: JSONL stores one JSON object per line for streaming and log pipelines, and YAML is a more human-friendly alternative for configuration files. When an API returns fields you do not understand, the formatted structure makes it clear whether they are nested objects, arrays, or optional values that may be absent on some responses. This is also the point where you verify the data against its contract. If you have a schema or documentation for the endpoint, walk the formatted payload against it field by field, and confirm types: a string where a number belongs, an object where an array belongs, and null where a value is required are the subtle failures that formatted viewing reveals. Keep the minified version around for anything you will store or transmit, and keep the formatted version in your notes. Formatting is the precondition for every other JSON task — schema validation, transformation, migration, and debugging all assume you can see and reason about the structure — so it belongs at the front of the workflow, every time.

Worked Example: A Messy API Response

Consider the kind of payload that ends up in a formatter every day: a single-line response like {"status":"ok","data":{"users":[{"id":1,"name":"Ada","email":"ada@example.com"},{"id":2,"name":"Grace","email":null}],"total":2}} pasted straight from a terminal. As one line, the structure is invisible and an error hides easily. The formatter lays it out into an object with a status field, a nested data object, a users array holding two objects, and a total field. Now the shape is obvious: the email field is null on the second user, and if your code assumes email is always a string, that is the bug the formatted view exposes before you write a single line. The same payload also demonstrates the pitfalls described above: if the original log line ended with a comma after the second user object, a human might miss it, but the formatter rejects it instantly at the exact position. And if you only need the user ids, the formatted tree shows you that they sit at data.users[*].id, which is precisely the path you would use in code. Formatting is not decoration; it is the difference between a payload you have to guess at and a payload you can read.

JSON Formatter & Validator

Format, validate, and minify JSON data. Pretty-print or compress JSON instantly in your browser.

Use the tool