JSON Formatter & Validator→Specialized Version
{ }

JSON Validator

Validate JSON syntax

JSON Validator

Validate JSON syntax and identify errors in your JSON data. This tool checks for proper formatting, missing brackets, invalid characters, and other common JSON mistakes.

Common JSON Errors

ErrorCauseFix
Unexpected tokenSyntax errorCheck for typos
Unterminated stringMissing quoteClose all strings
Trailing commaComma after last itemRemove trailing comma
Invalid characterNon-JSON characterUse proper escaping
Missing colonKey without valueAdd : after key

Valid JSON Rules

``javascript // Keys must be strings with double quotes { "name": "John" } // ✓ Valid { name: "John" } // ✗ Invalid

// Strings must use double quotes { "name": "John" } // ✓ Valid { "name": 'John' } // ✗ Invalid

// No trailing commas { "a": 1, "b": 2 } // ✓ Valid { "a": 1, "b": 2, } // ✗ Invalid

// No comments { "a": 1 } // ✓ Valid { "a": 1 } // note // ✗ Invalid `

Validation Code

`javascript function validateJSON(jsonString) { try { JSON.parse(jsonString); return { valid: true }; } catch (error) { return { valid: false, error: error.message, position: error.message.match(/position (\d+)/)?.[1] }; } }

// Example const result = validateJSON('{"name": "John", }'); // { valid: false, error: "Unexpected token }", position: 17 } `

JSON Data Types

TypeExampleNotes
String"hello"Double quotes only
Number42, 3.14No quotes, no leading zeros
Booleantrue, falseLowercase only
NullnullLowercase only
Array[1, 2, 3]Square brackets
Object{"a": 1}Curly braces
Use this validator to ensure your JSON is syntactically correct.

Numbers Are the Recurring Problem

A JSON number is an IEEE 754 double. Three consequences that bite in production:

ValueWhat happens
Integers above 2⁵³Silently lose precision — send IDs as strings
Money as a float0.1 + 0.2 = 0.30000000000000004
Leading zeros007 is invalid JSON; "007" is a string
NaN and InfinityNot valid JSON at all
Twitter hit the first one publicly: 64-bit tweet IDs arrived in JavaScript rounded, so the API began sending an id_str alongside every id.

Keys, Order and Duplicates

Objects are formally unordered, though every JavaScript engine preserves insertion order for string keys — with one exception: integer-like keys sort numerically and come first.

`javascript JSON.stringify({ b: 1, 2: 2, a: 3 }); // {"2":2,"b":1,"a":3} `

Duplicate keys are not an error in the spec, and JSON.parse keeps the last one. Two parsers can legitimately disagree about which value wins, which has been the basis of real request-smuggling attacks.

Rules That Prevent Most JSON Bugs

RuleWhy
No trailing commas{"a": 1,} is invalid JSON, though JavaScript accepts it in object literals
Double quotes only{'a': 1} is not JSON
Keys must be quoted{a: 1} is a JavaScript object, not JSON
No commentsThere is no comment syntax; JSON5 and JSONC are different formats
No undefined, NaN, InfinityJSON.stringify silently drops or nulls them
Numbers are IEEE 754 doublesIntegers above 2⁵³ lose precision — send them as strings

Parsing Safely

`javascript try { const data = JSON.parse(text); } catch (error) { // The message names the character offset, which is the fastest way // to find an unescaped quote in a large document. console.error(error.message); } `

JSON.parse` throws on invalid input rather than returning null, so it always belongs in a try/catch when the source is a file, a request body or a clipboard paste.

Frequently Asked Questions

What makes JSON invalid?

Common causes: single quotes instead of double quotes, trailing commas, comments, unquoted keys, missing colons or brackets, undefined/NaN values, and special characters without escaping. JSON has strict syntax rules compared to JavaScript object literals.

Why won't my JSON parse?

Check for: 1) Single quotes (use double), 2) Trailing commas, 3) Comments (not allowed), 4) Unescaped special characters, 5) Missing brackets or braces. The error message usually indicates the position of the first error.

Is JSON the same as a JavaScript object?

No, JSON is stricter. JavaScript objects allow single quotes, trailing commas, unquoted keys, and methods. JSON requires double-quoted strings, no trailing commas, quoted keys, and only data (no functions). JSON is a data format; JavaScript objects are code.

Related Tools

Explore other tools you might find useful:

More JSON Formatter & Validator tools

You might also need