JSON Formatter & Validator — Free Online Tool
Format, validate, and minify JSON instantly. Syntax highlighting, error detection with line numbers, and stats — all 100% client-side.
// Formatted JSON will appear here
What is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format originally derived from JavaScript's object literal syntax. Defined in RFC 8259, JSON represents data as key-value pairs (objects) and ordered lists (arrays). It is the dominant format for REST APIs, configuration files, and data serialization because virtually every modern programming language includes a built-in JSON parser.
JSON supports six primitive types: string, number, boolean (true/false), null, object (curly braces), and array (square brackets). All strings and all object keys must be enclosed in double quotes — single quotes are not valid JSON.
Common JSON Syntax Errors
The JSON specification is deliberately strict, which means small mistakes cause a complete parse failure. The most frequent causes of invalid JSON are:
- Trailing commas: A comma after the last element of an object or array —
{"a": 1,}— is not permitted in JSON. It is valid in JavaScript object literals and many languages but explicitly disallowed by the JSON spec. - Single-quoted strings: JSON requires double quotes for all strings and keys. Writing
{'key': 'value'}is invalid; it must be{"key": "value"}. - Unquoted keys: Object keys must always be quoted strings.
{name: "Alice"}is invalid JavaScript-style shorthand — JSON requires{"name": "Alice"}. - JavaScript comments: JSON does not support
// single-lineor/* block */comments. If you need comments in config files, consider JSONC or JSON5 — both require a dedicated parser and are not interchangeable with standard JSON. - Undefined values:
undefinedis a JavaScript concept; it has no representation in JSON. Keys withundefinedvalues are silently dropped byJSON.stringify(). - Unescaped special characters: Certain characters inside strings must be escaped:
\"(double quote),\\(backslash),\n(newline),\t(tab). Raw newlines inside a string literal are not allowed.
JSON.parse and JSON.stringify in JavaScript
JavaScript provides two built-in methods for working with JSON:
// Parse a JSON string into a JavaScript object const data = JSON.parse('{"name":"Alice","age":30}'); console.log(data.name); // "Alice" // Stringify a JavaScript object into a JSON string const json = JSON.stringify(data, null, 2); // 2-space indent // Always validate with try/catch try { const parsed = JSON.parse(userInput); } catch (e) { console.error('Invalid JSON:', e.message); } // Replacer function to filter keys const filtered = JSON.stringify(data, ['name']); // '{"name":"Alice"}'
Frequently Asked Questions
What is JSON and why is it used?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format derived from JavaScript object syntax. It uses key-value pairs and ordered lists, making it easy for both humans to read and machines to parse. JSON is the dominant format for REST APIs, configuration files, and data storage because virtually every programming language has a built-in JSON parser.
How do I validate JSON online?
Paste your JSON into the input field above and click Validate. The tool uses JSON.parse() to check your JSON and, if invalid, reports the exact syntax error with a line and column number. Common issues include trailing commas, single-quoted strings, unquoted keys, and JavaScript comments — none of which are valid JSON.
What is the difference between JSON and XML?
JSON is generally more compact, faster to parse, and easier to read than XML. XML uses verbose opening and closing tags and supports attributes, namespaces, and comments. JSON maps directly to data structures (objects and arrays) found in most languages. JSON has largely replaced XML for REST APIs, but XML is still used in SOAP services, document formats (SVG, DOCX), and enterprise systems.
Why does JSON not allow trailing commas?
Trailing commas (a comma after the last item in an object or array) are not valid in the JSON specification (RFC 8259). This is a strict design decision to simplify parsers. JavaScript itself allows trailing commas in array and object literals, but JSON.parse() will throw a SyntaxError. If you need a more permissive format, consider JSON5 or JSONC (JSON with Comments), though these require special parsers.
Related Developer Tools
- Base64 Encoder / Decoder — encode and decode Base64 strings instantly, including URL-safe variants
- URL Encoder / Decoder — percent-encode and decode URL components and query strings
- JWT Decoder & Inspector — decode JWT tokens, inspect claims and expiry countdown
- Regex Tester — test regular expressions with live match highlighting and capture group breakdown