Format, validate, and minify JSON instantly. Highlight errors, prettify with indentation, and convert between compact and readable JSON.
JSON Formatter & Validator
Ad · 336x280
JSON Formatting and Validation
JSON (JavaScript Object Notation) is the universal data format for APIs, configuration files, and data storage. This formatter transforms compact or malformed JSON into readable, indented output — and catches syntax errors before they crash your code.
JSON Syntax Rules
Keys must be quoted with double quotes — single quotes are invalid
No trailing commas after the last element in an array or object
Strings must use double quotes; escape special chars with backslash
Numbers: no leading zeros, no NaN/Infinity (use null instead)
Prettified JSON (with indentation and line breaks) is human-readable but adds whitespace bytes. Minified JSON strips all whitespace, reducing file size by 30–50%. Use prettified JSON for debugging and config files; minified JSON for API responses and production bundles where bandwidth matters.
Common JSON Errors
SyntaxError: Unexpected token — often a trailing comma, single quote, or unquoted key
Unexpected end of JSON input — truncated JSON, usually from an API response cut off mid-transfer
SyntaxError at position N — count characters from the start to position N to find the issue
Frequently Asked Questions
JSON is a text format — a string. JavaScript objects are in-memory data structures. JSON requires double-quoted keys and doesn't support functions, undefined, or comments. A JS object literal uses single or double quotes, allows trailing commas (modern JS), and can have methods. Convert between them with JSON.parse(jsonString) and JSON.stringify(jsObject).
No — standard JSON does not support comments. This is a deliberate design choice by Douglas Crockford to keep the format simple. If you need comments in JSON-like config files, use JSONC (JSON with Comments, used by VS Code settings), JSON5, or YAML. Some tools like VS Code's tsconfig.json support JSONC comments even though they appear to be standard JSON.
Common causes: (1) Single quotes instead of double quotes — 'key' should be "key". (2) Trailing comma — {"a":1,} should be {"a":1}. (3) Unquoted key — {key:"value"} should be {"key":"value"}. (4) Missing comma between items. Paste into this formatter — the error message includes the position of the invalid character to pinpoint the issue.
JavaScript: JSON.stringify(obj, null, 2). Python: json.dumps(obj, indent=2). PHP: json_encode($obj, JSON_PRETTY_PRINT). Ruby: JSON.pretty_generate(obj). Go: json.MarshalIndent(obj, '', ' '). Java: new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(obj). The indentation argument (2 or 4 spaces) is the standard pretty-print format.