Guide

How to Validate JSON Online and Fix Syntax Errors

Invalid JSON is one of the most common causes of API errors, configuration failures, and data import problems. A single misplaced comma, missing quote, or unquoted key can break an entire payload. This guide shows how to validate JSON online with line numbers, understand parser messages, and fix the most common syntax mistakes.

Last updated: June 21, 2026

Share:

Use the free tool

JSON Validator with Line Numbers

Paste any JSON to check syntax, find missing braces, trailing commas, quote mistakes, and parser errors instantly. Free, browser-based, no data leaves your machine.

Open the live tool →

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 with Line Numbers

  • Step 1: Open the JSON Validator at /developer-tools/json-validator.
  • Step 2: Paste your JSON data into the input area.
  • Step 3: Click Validate JSON to run the syntax checker and display either 'Valid JSON' or an error message with the line and position of the problem.
  • Step 4: If errors are found, inspect the highlighted line and the line above it. JSON parser errors often appear just after the actual missing comma, quote, or brace.
  • Step 5: Once valid, use the JSON Formatter at /developer-tools/json-formatter to pretty-print the data for readability.

What the line number usually means

  • If the parser points to the beginning of a line, the real mistake is often on the line above where a comma, quote, or closing bracket is missing.
  • An 'unexpected end of JSON input' error usually means an object, array, or string opened earlier and never closed.
  • An 'unexpected string' error often means two values are next to each other without a comma between them.
  • An error at character 1 can mean the pasted content starts with a comment, BOM, or non-JSON text before the first { or [.

The 10 Most Common JSON Syntax 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.

How to fix trailing commas, unquoted keys, and single quotes

Trailing commas are the fastest error to miss because JavaScript accepts them in many places. JSON does not. If the validator points near a closing brace or bracket, look for a comma immediately before that closing character and remove it.

Unquoted keys usually come from JavaScript object snippets copied from code, browser consoles, or documentation. Convert every key into a double-quoted string before sending the payload to an API, storing it in a .json file, or running schema validation.

Single quotes are also JavaScript syntax, not JSON syntax. Replace single-quoted keys and string values with double quotes, then validate again before formatting the payload.

How to validate an API response or config file

  • Copy only the JSON body, not HTTP headers, status labels, logs, stack traces, or markdown fences.
  • Run /developer-tools/json-validator first so malformed JSON is separated from API contract problems.
  • If the syntax is valid but the endpoint still rejects the payload, validate the object shape in /developer-tools/json-schema-validator.
  • If you copied from a chat tool or documentation page, remove smart quotes, comments, and surrounding explanation text before validating.

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.

A practical browser debugging order

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.

When syntax is valid but the payload still fails

A payload can be perfectly valid JSON and still be rejected because a required field is missing, a value has the wrong type, or an enum no longer matches the API contract. That is not a parser problem anymore.

Once /developer-tools/json-validator reports valid JSON, stop rechecking commas and quotes and move to /developer-tools/json-schema-validator or /guides/how-to-validate-api-payloads-with-json-schema. That handoff saves time and makes the next debugging step more honest.

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.

Common Questions

Frequently asked questions

What is the fastest way to validate JSON online?
Paste the payload into a JSON validator with line numbers, run the syntax check, then inspect the highlighted line and the line above it for missing commas, quotes, braces, or extra text.
Why does my JSON validator show an error on the wrong line?
Parser errors often appear where parsing finally failed, not where the mistake started. If the error is at the start of a line, check the previous line for a missing comma, quote, or closing bracket.
Should I format JSON before validating it?
Validate syntax first. Once the JSON parses, use a formatter to make the nesting easier to read. If the valid JSON still fails an API contract, use JSON Schema validation next.