JSON Formatter & Validator
Format, validate, and minify JSON online. Paste your JSON to instantly pretty-print it, check for errors with line numbers, and convert between JSON and PHP arrays.
What is a JSON Formatter?
A JSON formatter takes raw or minified JSON and adds consistent indentation and line breaks, turning a wall of text into a readable, hierarchical structure. JSON (JavaScript Object Notation) is the standard data format for web APIs, config files, and databases - but responses and logs rarely arrive pre-formatted. This free online JSON formatter also validates your JSON on every keystroke, showing the exact line and character where a syntax error occurs so you can fix it in seconds rather than counting braces manually.
Common JSON syntax errors explained
The most frequent JSON mistakes are: trailing commas after the last object key or array item (valid in JavaScript, invalid in JSON); single-quoted strings - JSON requires double quotes for both keys and values; unescaped backslashes inside strings; comments - the JSON spec does not allow them; and leading zeros on numbers. If you paste JSON from a JS source file, be aware that JS object literals use bare identifiers as keys ({name: "John"}) which is not valid JSON.
Frequently Asked Questions
What is the difference between formatting and minifying JSON?
Formatting (pretty-printing) adds indentation and newlines for human readability. Minifying removes all whitespace to reduce file size - useful for API payloads sent over the network. The data is identical; only the whitespace differs. A 10 KB formatted JSON file typically minifies to under 3 KB.
Can I use JSON with comments?
Standard JSON (RFC 8259) does not support comments. For config files that need comments, JSONC (JSON with Comments) is used by VS Code's settings.json and TypeScript's tsconfig.json. YAML and TOML both support comments natively. Strip comments before pasting into this formatter.
What does "unexpected token" mean in a JSON error?
The parser found a character it didn't expect. Check the line before the reported error - a trailing comma or missing closing bracket on the previous line is usually the culprit. The error position marks where parsing stopped, not necessarily where the mistake was made.
How do I validate JSON in PHP or Laravel?
Use json_validate($string) in PHP 8.3+, or check json_last_error() === JSON_ERROR_NONE after json_decode() in older versions. In Laravel Form Requests, add Rule::json() to your validation rules. For API responses, response()->json($data) automatically encodes valid PHP arrays.