JSON Formatter

Format messy JSON into readable, indented output, minify it back to one line, and validate it with error messages that show the exact line and column of the problem.

Readable JSON in one click

JSON from an API or log file usually arrives as one dense line. Paste it here to format it with clean indentation, or minify readable JSON back into a single line for transport. If the JSON is broken, the tool tells you what the parser objected to and where, instead of a vague failure.

Common JSON mistakes this catches

  • Trailing commas after the last item in an object or array.
  • Single quotes or unquoted keys.
  • Missing commas between items, and unmatched braces or brackets.
  • Comments pasted in from JavaScript, which JSON does not allow.

How formatting and validation work under the hood

When you press Format, the tool hands your text to the strict JSON parser built into your browser. The parser reads the text character by character, building objects, arrays, strings, numbers, booleans and null values, and it stops at the first thing it cannot make sense of. That stopping point is what the error message reports, converted here into a line and column so you can jump straight to the problem. If the text parses cleanly, the tool writes the data back out with your chosen indentation, two spaces, four spaces or tabs. Minifying does the same round trip but writes with no optional whitespace at all. Because the output is regenerated from the parsed data rather than tidied up as raw text, formatting can never accidentally change a value, reorder is not applied, and invalid input can never slip through dressed up as valid output.

Practical tips for debugging faster

  • Start at the reported position, then look just before it: parsers often notice a mistake one token late, so a missing comma usually hides at the end of the previous line.
  • Format in stages when editing by hand: paste, format, make one change, format again. If it suddenly fails, your last change is the culprit and the search area stays small.
  • Watch string escapes: a backslash, a quote or a line break inside a value must be escaped. File paths copied from Windows and text with quotes are the usual troublemakers.
  • Check the very end of the document: truncated copies from logs and terminals often cut the closing brackets. Counting opening and closing braces after formatting is a quick sanity check.
  • Minify before measuring: if you are checking a payload size limit, minified output shows the true transfer size with no pretty printing overhead included.

A worked example

An API returns this in one line: a user object with an id of 42, a name, an active flag set to true, and a tags array holding admin and editor. Formatted with two space indentation, it becomes about ten short lines where the nesting is obvious at a glance, and you can see immediately that tags is an array while the other values are plain fields. Now add a trailing comma after the last tag, an easy slip when copying from JavaScript. Validation fails and the message points to the position right after that comma, around line 8 depending on layout. Delete the comma, format again, and the same document minifies back to a single line of about 90 characters, ready to paste into a request body or a configuration field with a strict size limit.

More mistakes worth knowing

  • Using undefined, NaN or functions: these exist in JavaScript but have no place in JSON. Convert undefined to null and leave functions out entirely.
  • Writing numbers with leading zeros or bare decimal points: values such as 007 or .5 are rejected. Write 7 and 0.5 instead.
  • Mixing up similar looking characters: smart quotes pasted from a word processor look like double quotes but are not. Retype quotes in a plain text editor if validation keeps failing on a line that looks fine.
  • Assuming formatted means correct data: validation proves the structure is legal, not that the values are right. A price stored as a string will format beautifully and still break code that expects a number.
  • Editing the minified version by hand: one deleted character in a single line document is hard to spot. Keep a formatted copy as your working version and minify only for delivery.

Working with encoded data as well? The Base64 Encoder and Decoder handles the strings that often travel inside JSON payloads.

Frequently asked questions

What does JSON validation check?

The validator parses your text with the same strict rules every JSON parser uses: keys must be in double quotes, strings cannot use single quotes, trailing commas are not allowed, and brackets must match. When something is wrong, the error message points at the position of the problem so you can find it quickly.

What is the difference between formatting and minifying?

Formatting (or pretty-printing) adds line breaks and indentation so humans can read the structure. Minifying removes all unnecessary whitespace so the same data takes the fewest possible bytes, which is how JSON is usually sent between servers.

Is my JSON uploaded anywhere?

No. Parsing and formatting happen in your browser, so it is safe to use with configuration files, API responses and other data you would not paste into a stranger's server.

Why does my JSON fail with single quotes?

The JSON standard requires double quotes around keys and string values. Single-quoted text is valid in JavaScript object literals but not in JSON. Replace single quotes with double quotes and escape any double quotes inside the values.