MergeJSON

How to Validate JSON (and Fix the Errors Fast)

Learn how to validate JSON, read parser error messages, and fix the most common syntax mistakes — trailing commas, missing quotes, and more.

Published February 5, 2026

A single misplaced character can make an entire JSON document unparseable. Validating JSON — confirming it follows the format’s rules — is therefore a daily task for anyone working with APIs, config files, or data exports. This guide shows you how to validate JSON quickly and how to decode the error messages parsers give you.

What “valid JSON” means

Valid JSON satisfies a small, strict grammar:

  • The whole document is a single value (usually an object or array).
  • Strings use double quotes only.
  • Object keys are quoted strings.
  • No trailing commas after the last element.
  • No comments.
  • Numbers follow standard notation (no leading zeros, no + prefix, no hex).

If any rule is broken, parsing fails — and the error message points you to the problem.

Three ways to validate

1. In the browser, instantly

The quickest check is to paste your JSON into a tool that validates as you type. Our merge tool does exactly this: each input is parsed live, and invalid JSON is flagged with the exact line and column of the error before you do anything else. No installation, no upload.

2. In JavaScript

JSON.parse throws a SyntaxError on invalid input, so a tiny wrapper validates anything:

function isValidJson(text) {
  try {
    JSON.parse(text);
    return true;
  } catch (e) {
    console.error(e.message); // includes a position
    return false;
  }
}

3. On the command line

jq validates and pretty-prints in one step:

jq . data.json   # prints formatted JSON, or an error with a line number

Python’s built-in tool works too:

python -m json.tool data.json

Reading parser errors

Error messages look intimidating but follow patterns. A few common ones:

  • Unexpected token } in JSON at position 42 — usually a trailing comma just before the brace, or a missing value.
  • Unexpected string in JSON — often a missing comma between two key/value pairs.
  • Unexpected end of JSON input — a brace or bracket was never closed.
  • Expected property name or '}' — a key is missing its quotes, or there is a stray comma.

The number in “position N” is a character offset. Tools that translate that into a line and column (like the live validation in our editor) make the fix far faster.

The most common mistakes

By a wide margin, these four account for most invalid JSON:

  1. Trailing commas[1, 2, 3,] or { "a": 1, }. Legal in JavaScript, illegal in JSON.
  2. Single quotes{ 'name': 'Ada' }. JSON requires double quotes.
  3. Unquoted keys{ name: "Ada" }. Keys must be quoted strings.
  4. Comments// like this. Not allowed in standard JSON.

We cover fixes for each in depth in common JSON errors and how to fix them.

Validation before merging

Validation matters most right before you transform data. If you merge two files and one is invalid, the result is garbage — or the merge silently drops content. That is why our merge tool validates every input before merging and refuses to proceed until each one is well-formed, telling you precisely which file and which line is at fault.

Schema validation: the next level

Syntax validity (“is this parseable?”) is different from schema validity (“does this match the shape I expect?”). For the latter, JSON Schema lets you declare required fields, types, and constraints, then validate documents against them with libraries like ajv (JavaScript) or jsonschema (Python). Most day-to-day work only needs syntax validation, but schema validation is invaluable for API contracts.

Takeaway

Validating JSON is fast once you know the rules and can read parser errors. For instant, private validation while you work — especially before merging files — paste your JSON into the tool and let it flag problems line by line.

Ready to merge your JSON?

Combine files or snippets in your browser — free and private.

Open the merge tool

Keep reading