JSON Formatter & ValidatorSpecialized 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

| Error | Cause | Fix | Unexpected tokenSyntax errorCheck for typos Unterminated stringMissing quoteClose all strings Trailing commaComma after last itemRemove trailing comma Invalid characterNon-JSON characterUse proper escaping | Missing colon | Key without value | Add : 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

| Type | Example | Notes | 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.

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:

Related Calculators