Guide
How to Validate JSON — Finding & Fixing Syntax Errors
Invalid JSON is one of the most common causes of API errors, configuration failures, and data import problems. A single misplaced comma or missing quote can break an entire application. This guide teaches you how to validate JSON, understand error messages, and fix the most common mistakes.
Last updated: April 17, 2026
What Is Valid JSON?
JSON (JavaScript Object Notation) has strict syntax rules. Unlike JavaScript, JSON does not allow trailing commas, single quotes, comments, or unquoted keys. Valid JSON must follow these rules exactly: strings use double quotes, keys are always quoted strings, values can be strings, numbers, booleans, null, arrays, or objects.
A valid JSON document is either an object ({}) or an array ([]). The top level cannot be a bare string, number, or boolean — although some parsers accept these, they're technically not valid JSON per the RFC 8259 specification.
How to Validate JSON Online
- Step 1: Open the JSON Validator at /developer-tools/json-validator.
- Step 2: Paste your JSON data into the input area.
- Step 3: The tool instantly validates the syntax and displays either 'Valid JSON' or an error message with the exact location of the problem.
- Step 4: If errors are found, the error message includes the line number and character position. Fix the issue and the tool re-validates in real time.
- Step 5: Once valid, use the JSON Formatter at /developer-tools/json-formatter to pretty-print the data for readability.
The 10 Most Common JSON Errors
- 1. Trailing comma — A comma after the last item in an object or array: {"a":1,} is invalid. Remove the final comma.
- 2. Single quotes — JSON requires double quotes: {'name':'Alice'} must be {"name":"Alice"}.
- 3. Unquoted keys — {name:"Alice"} is invalid. Keys must be quoted: {"name":"Alice"}.
- 4. Missing comma between items — {"a":1 "b":2} needs a comma: {"a":1, "b":2}.
- 5. Missing closing bracket — Every { needs a }, and every [ needs a ]. Check for mismatched pairs.
- 6. Comments — JSON does not support comments. Remove any // or /* */ before parsing.
- 7. Undefined/NaN values — JSON only allows null, not undefined, NaN, or Infinity.
- 8. Incorrect escaping — Backslashes in strings must be escaped: use \\ not \. New lines must be \n, not literal line breaks.
- 9. Extra data after root — Having content after the closing } or ] makes the document invalid.
- 10. BOM (Byte Order Mark) — Some editors add invisible BOM characters at the start of files. These cause 'unexpected token' errors.
JSON vs JavaScript Objects
A common source of confusion is that JSON looks like JavaScript objects but has stricter rules. In JavaScript, {name: 'Alice', age: 30,} is perfectly valid — unquoted keys, single quotes, and trailing commas are all allowed. In JSON, none of these are permitted.
When copying data from JavaScript code, browser dev tools, or console output, always validate it as JSON before using it in configuration files or API requests. Our formatter tool will highlight exactly where the JavaScript-specific syntax needs to be converted to valid JSON.
Validating JSON in Code
In JavaScript/TypeScript, use try/catch with JSON.parse(): try { JSON.parse(text); } catch(e) { console.error(e.message); }. In Python: import json; json.loads(text). In command line: echo '{...}' | python -m json.tool.
For configuration files like package.json, tsconfig.json, or .eslintrc.json, most editors (VS Code, JetBrains) provide real-time JSON validation with inline error markers. Enable the built-in JSON language mode for automatic validation.
Frequently Asked Questions
- Q: Is JSONC (JSON with Comments) valid JSON? — No. JSONC is an extension supported by some tools (like VS Code's settings files), but standard JSON parsers will reject it.
- Q: Can JSON have duplicate keys? — The spec doesn't explicitly forbid it, but behavior is undefined. Most parsers keep the last value, silently dropping earlier ones. Avoid duplicate keys.
- Q: What's the maximum size of a JSON file? — There's no specification limit, but practical limits depend on your parser and available memory. Browser-based tools handle files up to about 10MB comfortably.
- Q: Does whitespace matter in JSON? — No. Whitespace (spaces, tabs, newlines) between tokens is ignored. Minified JSON is equally valid as pretty-printed JSON.
Take Action
Tools and pages referenced in this guide
Keep Reading
More developer tools guides and comparisons
How to Format JSON Safely Online
Best practices for formatting, validating, and cleaning up JSON data without exposing sensitive information.
How to Decode JWT Tokens
Understand JWT structure, signing algorithms, security best practices, and how to decode tokens safely with our free tool.
Regex Basics for Beginners
Learn regular expressions from scratch — syntax, quantifiers, groups, 10 practical patterns, and common mistakes to avoid.
Follow Updates
Get new tools and guides as they ship
Follow our updates page for new launches, privacy-first workflows, and editorial guides. RSS is live now, and email digests appear when a deployment has a configured provider.