JSON Formatter

Valid JSON—
Top-level keys—
Nesting depth—

How JSON Formatter is calculated: Parse with JSON.parse, then print with 2-space indent; validity = parses without error; depth = deepest nesting level of objects and arrays.

What is a JSON formatter?

A JSON formatter takes a block of JSON — usually a single long line with no spaces — and prints it neatly, with each key on its own line and each level indented by two spaces. The default text on this page, {"name":"Ada","age":36,"city":"London"}, becomes three readable lines. It also tells you whether the JSON is valid, how many top-level keys it has, and how deep it nests.

The need comes up constantly for anyone who works with data. APIs return JSON as one long line. Config files, log files, and saved data are all JSON. A developer who opens a minified response sees a wall of text; a developer who formats it sees a structure. The difference is the difference between guessing and reading.

This formatter covers the checks people actually need: validity, top-level key count, and nesting depth, plus the clean 2-space output itself. Paste your JSON and everything updates live as you type. Everything runs in your browser — your data never leaves your device, nothing is stored, and there is no account to create.

How a JSON formatter works

The formatter does two things. First it parses your text with JSON.parse, the standard JSON reader built into every browser. If the text parses, it is valid JSON; if it throws an error, it is not, and the error message tells you what went wrong and roughly where. The default text parses cleanly, so it shows Valid: Yes, with 3 top-level keys and a depth of 1.

Then it prints the parsed value back out with JSON.stringify and a 2-space indent. That is what turns one long line into a readable block. The keys stay in the same order, the values stay the same, and nothing is added or lost — the output is the same data, just laid out for human eyes.

Depth is the deepest nesting level. The default text has a depth of 1, because its values are plain strings and numbers. A nested example like {"a":{"b":[1,2,{"c":3}]}} has a depth of 4: the outer object, the object under a, the array under b, and the object inside the array. Key count is simpler: it counts the keys of the top-level object only, so the nested example has 1 key, not 4.

The JSON rules that trip people up

The most common error is a missing or extra comma. JSON is strict about commas: every pair of values needs one between them, and a trailing comma after the last value is an error. The formatter will tell you the JSON is invalid, but it will not fix the comma for you — read the error message, find the spot, and fix it by hand.

Second: single quotes. JSON strings must use double quotes. {'name': 'Ada'} looks like JSON, but it is not — the parser rejects it. Change the quotes to double and it parses. The same goes for unquoted keys: {name: "Ada"} is valid JavaScript, but it is not valid JSON.

Third: comments. JSON has no comments. A // note or a /* block */ inside JSON is an error, even though it works in JavaScript. If your config file has comments, strip them before pasting. A base64 encoder decoder can carry JSON safely inside another format when you need to move it, and a word counter can check the size of the same text once it is formatted.

A worked example: reading an API response

Here is a real situation where a JSON formatter earns its keep. You call an API and get back a single line: {"name":"Ada","age":36,"city":"London"}. It is valid, but you cannot read it at a glance. Paste it in and the formatter prints it as three lines, one key each, indented by two spaces.

The counts tell the story: Valid Yes, 3 top-level keys, depth 1. That means the response is a flat object with three fields — name, age, and city — and no nesting at all. You know in one second what the API returned, without counting braces.

Try a nested one. Paste {"a":{"b":[1,2,{"c":3}]}} and the formatter says Valid Yes, 1 top-level key, depth 4. The single key is a, and the nesting goes four levels deep: object, object, array, object. If your code expects a flat object and gets depth 4, you have found your bug. And an invalid example like {name: Ada} shows Valid No with 0 keys and depth 0 — the missing quotes are the problem.

Who uses a JSON formatter, and why

Developers are the biggest users. Every API returns JSON, every config file is JSON, and every log line with structured data is JSON. A developer who formats a response reads it in seconds; a developer who stares at a minified line wastes minutes and misses fields.

Data workers are the second group. Analysts, testers, and support staff all read JSON when something goes wrong — a failed import, a broken integration, a strange error. The validity check tells them whether the data is broken or the code is broken, which is the first question in any debugging session.

Students and hobbyists are the third group. Anyone learning to code meets JSON in the first month, and a formatter is the fastest way to see how it works. The formatter on this page handles all three uses — paste, check, copy the clean output — which covers ninety percent of what anyone needs.

Support staff are a fourth group, and they use the formatter to read what a customer pasted into a ticket. A minified error payload means nothing to a support agent; the same payload formatted with two-space indent shows the failing field in seconds. Formatting turns a wall of text into a readable report, and that is often the whole job.

JSON formatter vs other developer tools

A JSON formatter reads and prints data; other developer tools move it or hide it. The same developer-tools family on this site does both jobs. A base64 encoder decoder turns JSON into a single safe string for transport — useful when JSON has to travel inside a URL or a header. A random number generator makes test data to fill a JSON object with.

The difference matters for workflow. Format first, then move: if the JSON is invalid, no amount of encoding will fix it. Check validity here, fix the error, and only then encode it or send it on. A formatter is the first stop, not the last.

Validation is the part people skip, and it is the part that saves the most time. A single missing quote can break a whole integration, and the formatter catches it in a second. And a password generator answers a different need entirely: making secrets to put in the config, not reading the config itself.

Minified JSON is the other half of the story. APIs send JSON without spaces to save bandwidth, which is right for machines and wrong for humans. The formatter is the bridge between the two: the machine sends one long line, and the human reads a neat block. Neither side has to change what it does, and both sides get what they need.

Common JSON mistakes

The most common mistake is the trailing comma. {"a":1,} is invalid JSON — the comma after the last value is an error. JavaScript allows it; JSON does not. Remove the comma and it parses. This one error accounts for a large share of all invalid JSON.

Second: single quotes around strings. JSON demands double quotes. {'a': 1} is invalid; {"a": 1} is valid. If your JSON came from a Python script or a hand-written note, check the quotes first.

Third: numbers with leading zeroes. 01 is not a valid JSON number; 1 is. The same goes for NaN and Infinity — they are JavaScript values, not JSON values. Use null when a value is missing, not NaN.

Fourth: pasting JSON with a byte-order mark or invisible characters. Copying from some editors adds hidden characters at the start of the text, and the parser rejects them. If the formatter says invalid and the JSON looks fine, paste it into a plain text editor first, then copy it back.

How to use this JSON formatter

Using this JSON formatter is simple. Paste your JSON into the box, or type it directly. The formatted output appears instantly in the box below, with validity, key count, and depth shown above it. There is no button to press and no form to submit.

To copy the result, use the Copy button next to the output box. To check another block, select all, delete, and paste the new one. The counts reset instantly. If the JSON is invalid, the output box shows the error message instead — read it, fix the spot it points to, and paste again.

Everything runs in your browser. No sign-up, no account, no data sent anywhere — your JSON never leaves your device. It works offline once the page has loaded, so you can use it on a plane, in a server room with no signal, or anywhere else you debug. Try it with something real before you need it: paste an API response, or a config file, and read it clean. Once you have used it twice, you will never read minified JSON again. JSON uses \u escapes for special characters; the unicode text converter shows what each code point means.

Frequently Asked Questions

It takes minified or messy JSON and prints it neatly, with each key on its own line and each level indented by two spaces. It also tells you whether the JSON is valid, how many top-level keys it has, and how deep it nests. The data itself does not change — only the layout does.

The usual causes are a trailing comma after the last value, single quotes instead of double quotes, unquoted keys, or comments inside the JSON. The formatter shows the parser's error message, which points at the problem. Fix that spot and paste again — most invalid JSON is one character away from valid.

Depth is the deepest level of objects and arrays inside each other. A flat object like {"name":"Ada"} has depth 1. A nested example like {"a":{"b":[1,2,{"c":3}]}} has depth 4. Deep nesting is not wrong, but it makes data harder to read and harder to use in code.

Yes. Everything runs in your browser — your JSON is never uploaded, stored, or sent anywhere. You can use it offline once the page has loaded, and you can paste sensitive data like API keys or user records without worrying about who sees it.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.