Tools · Text · JSON formatieren und validieren · Anleitungen · How to Format and Validate JSON (And Fix the Error When It's Not Valid)

How to Format and Validate JSON (And Fix the Error When It's Not Valid)

5 Min. Lesezeit

Paste JSON into the formatter and one of two things happens the moment you stop typing: it's pretty-printed with the indent width you picked, or you get the exact line and column where it stops being valid JSON. There's no Run button and no upload step - it happens live, in the browser, as you type or paste.

Paste JSON, get a formatted result or an exact error location A pipeline of three boxes: paste JSON into the textarea, the browser validates it live, then either a formatted or minified result appears with a copy button, or an invalid-JSON message shows the exact line and column of the problem. Paste JSON into the textarea Your browser validates it live Valid formatted + copy Invalid line and column shown
Nothing here needs a click. The result updates as you type, whichever way it goes.

Step 1 - paste the JSON

Drop the text into the input box. It accepts anything - a full API response, a single value, an object, an array - and there's no minimum or maximum shape it expects, because it doesn't try to guess what your JSON represents before checking it. An empty box shows nothing yet; that's deliberate, since a blank textarea isn't invalid JSON, it's just nothing to check.

Step 2 - read the result

The moment you stop typing, one of two things is on screen: a "Valid JSON" line with the formatted result underneath, or a message naming exactly what's wrong and where. A typical error reads something like "Not valid JSON - Unexpected token } at line 4, column 12" - the line and column come from walking the text and counting characters up to the position JSON.parse reported, not from guessing. On the rare browser whose error message doesn't include a position at all, the tool says so honestly instead of showing a location it can't back up.

One case worth knowing about explicitly: extremely deep nesting - thousands of arrays inside arrays inside arrays, the kind of pathological input nobody writes by hand but a buggy script might generate - can hit a stack-depth limit before a normal syntax error would even apply. That shows as its own message, "too deeply nested to process safely," rather than a raw crash.

Step 3 - switch modes if you need to

Format is the default and adds whitespace and line breaks so nested structure is visible. Minify strips all of that back out, useful when the destination is a config file, a URL parameter, or anywhere whitespace just adds bytes for no benefit. Switching between the two re-renders the same parsed value instantly - it isn't a second operation, just a different way of writing out the same result.

In Format mode, an indent selector picks 2 spaces, 4 spaces, or a tab character. 2 spaces is the default and matches what most style guides and formatters already use; pick whichever matches the file you're pasting into, since consistent indentation is the whole point of formatting in the first place.

Not sure which mode fits your situation? See Format vs Minify: which one you actually need.

Step 4 - copy the result

A Copy button sits at the top of the output (and the toolbar's main button copies it too) and puts the exact formatted or minified text on your clipboard, ready to paste back into wherever it came from. If the browser blocks the automatic copy for any reason, the tool says so and tells you to select the text and copy it by hand instead of failing silently.

Common mistakes this catches

A handful of habits from writing JavaScript object literals sneak into JSON constantly, and every one of them is invalid JSON even though they look completely reasonable to write:

A trailing comma after the last item in an object or array - {"a": 1, "b": 2,} - is legal in a JavaScript object literal and invalid in JSON. Single-quoted strings - {'name': 'value'} - are normal JavaScript and invalid JSON, which only allows double quotes. Unquoted object keys - {name: "value"} - are valid JavaScript shorthand and, again, invalid JSON, where every key must be a double-quoted string. Comments of any kind, // or /* */, aren't part of the JSON grammar at all, even though plenty of real-world config files that call themselves JSON quietly support them through a non-standard parser.

Every one of these gets reported the same way as any other syntax error - a specific line and column, not a generic rejection - which is usually enough on its own to recognize which habit slipped in this time.

What this tool won't do, on purpose

It checks strict JSON per RFC 8259, and only that. Comments, trailing commas, and unquoted keys - the kind of relaxed syntax some people write in JavaScript object literals out of habit - are reported as errors here, not quietly accepted. That's not a limitation someone forgot to handle; it's the honest answer for a validator whose whole job is telling you whether a file is actually valid JSON. If your file needs that leniency, it isn't JSON yet.

Large input is still handled, but very large pastes - several million characters - get a warning that things may run a little slower, since a browser tab has less headroom than a desktop editor. For anything in the size range an API response or a config file normally reaches, the check and the formatting happen close to instantly.

Nothing you paste here is uploaded anywhere. The validation runs with the same JSON.parse your browser already ships, entirely on your device - worth knowing if what you're debugging is a real response carrying real data, not a placeholder.

JSON formatieren und validieren kostenlos ausprobieren JSON formatieren und validieren

Ähnliche Tools