Paste JSON to indent it, minify it, or find out why it will not parse. When the input is broken, the error names the line where parsing stopped, and the mistake sits on that line or just before it. Often it is a trailing comma or a single-quoted string.
{"id":1,"name":"John Doe","roles":["admin","user"],"active":true,"meta":{"created":"2023-01-01","login_count":42}} {
"id": 1,
"name": "John Doe",
"roles": [
"admin",
"user"
],
"active": true,
"meta": {
"created": "2023-01-01",
"login_count": 42
}
} Look just before the reported spot. The error names the line where parsing stopped, which is usually one token after the real mistake. For example, a trailing comma is reported at the closing brace that follows it.
A minified response puts everything on one line. Indented with 2 spaces, 4 spaces or tabs, the nesting of objects and arrays shows at a glance.
Minify removes every space and line break outside strings. Use it before you paste JSON into a config value or an environment variable.
const raw = '{"id":1,"name":"John","roles":["admin","user"]}';
// Validate + pretty-print with 2-space indentation
try {
const data = JSON.parse(raw);
console.log(JSON.stringify(data, null, 2));
} catch (err) {
console.error("Invalid JSON:", err.message);
}
// Minify
console.log(JSON.stringify(JSON.parse(raw))); JSON.stringify's third argument is the indent: a number of spaces or a string such as "\t".
<?php
$raw = '{"id":1,"name":"John","roles":["admin","user"]}';
$data = json_decode($raw, true);
if (json_last_error() !== JSON_ERROR_NONE) {
die('Invalid JSON: ' . json_last_error_msg());
}
echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); JSON_PRETTY_PRINT always uses 4 spaces. Add JSON_THROW_ON_ERROR (PHP 7.3+) to get an exception instead of checking json_last_error().
import json
raw = '{"id":1,"name":"John","roles":["admin","user"]}'
try:
data = json.loads(raw)
except json.JSONDecodeError as e:
raise SystemExit(f"Invalid JSON at line {e.lineno} col {e.colno}: {e.msg}")
print(json.dumps(data, indent=2, ensure_ascii=False))
# From the shell, without writing a script:
# python3 -m json.tool input.json JSON (RFC 8259) is a strict subset of JavaScript's object syntax. Keys must be double-quoted strings, and values can only be objects, arrays, strings, numbers, true, false and null. There are no comments and no trailing commas. Most parse errors come from pasting a JavaScript object literal and expecting it to be JSON.
Keep the original file when it carries 64-bit IDs as bare numbers. Formatting is a parse-and-reserialize step, so a few surface details change even though the meaning does not. 1.0 comes back as 1, escapes such as \u00e9 are written as the plain character, and integers above 2^53 lose precision. Integer-like keys such as "2" also move to the front of their object.
This tool follows the specifications below. Read them when you need the exact normative wording, for example to settle an edge case between two implementations.
Yes. Invalid JSON shows an error with the line where parsing stopped and the browser's description of the problem. The usual causes are a missing comma, a trailing comma, or single quotes where JSON requires double quotes.
Yes. The Minify button removes every space and line break outside strings, which gives the smallest output for storage or transmission.
The dropdown offers 2 Spaces, 4 Spaces or Tab. Pick the one your project's style guide uses.
Ordinary keys keep their original order, and only whitespace and line breaks change. However, integer-like keys such as "2" and "10" move to the front in ascending order, because that is how JavaScript objects store them.
Yes. Click Load URL and enter a JSON endpoint; the fetch works when the server allows cross-origin requests. Otherwise, save the response and use Upload File.
Once the JSON parses, convert it: to CSV, to YAML, to a PHP array, to a JavaScript object. Or read it as a grid in the JSON table viewer.