How to Check Whether JSON Is Valid Before Sending It

Sending invalid JSON to an API returns an error — but often not a helpful one. The API doesn't know what you meant to send; it just knows it can't parse what it got. Catching the syntax error before the request goes out is faster than debugging a 400 response.

Why JSON breaks so easily

JSON has strict syntax rules. A single mistake — a trailing comma, a missing closing brace, single quotes instead of double quotes — makes the entire payload invalid. The parser rejects the whole document at the first error it encounters; it doesn't skip past problems.

Common syntax mistakes:

// Trailing comma (not allowed in JSON)
{"name": "Alice", "age": 30,}

// Single quotes (JSON requires double quotes)
{'name': 'Alice'}

// Unquoted key (JSON requires quoted keys)
{name: "Alice"}

// Missing closing brace
{"name": "Alice", "data": {"x": 1}

When validation saves most time

Validate JSON before: sending API requests, saving config files, importing structured data, pasting a payload into another tool.

It's especially useful when JSON was assembled by combining template strings with variables, copied from logs or documentation that might not be exactly valid JSON, or edited manually after being generated.

Validate before formatting

A JSON formatter that receives invalid JSON either fails silently, formats the error characters in confusing ways, or produces output that looks right but isn't. Validate first — confirm the structure is correct — then format for readability. This order matters.

{}
JSON validator
Paste JSON and see immediately whether it's valid, with error position for failures.
Open validator →

Reading validation error messages

A good JSON validator shows you where the error is, not just that there is one. Error messages typically reference a line number and character position. "Unexpected token , at line 4 position 18" means there's a comma at an unexpected position on line 4 — usually a trailing comma.

Work from the first error. JSON validation is often a cascade — one missing brace causes everything after it to be invalid, producing a list of errors when the actual problem is just one. Fix the first error and re-validate.

Frequently Asked Questions

How do I check if JSON is valid online? Paste your JSON into an online JSON validator and it will tell you immediately whether the syntax is correct. If there is an error, a good validator shows the line number and character position of the problem.

What is a JSON validator? A JSON validator checks whether a JSON document follows the correct syntax rules — properly paired braces and brackets, quoted keys, valid value types, no trailing commas, and no comments. It tells you whether the document can be parsed without errors.

Why does my JSON keep failing API requests? The most common reasons are a trailing comma after the last item, single-quoted strings instead of double quotes, a missing or extra brace or bracket, or a comment left in the file. Paste the payload into a JSON validator before sending to catch these before they hit the API.

What is the difference between a JSON validator and a JSON formatter? A validator checks whether the JSON is syntactically correct. A formatter adds indentation and line breaks to make valid JSON readable. The typical workflow is validate first to confirm the syntax is correct, then format to inspect the structure clearly.

Can valid JSON still break my application? Yes. A JSON validator only checks syntax. If a field has the wrong type, a required key is missing, or a value is out of the expected range, the JSON is still syntactically valid but may break the consumer. JSON Schema validation checks those semantic rules on top of the syntax check.

What is a trailing comma in JSON and why does it matter? A trailing comma is a comma after the last item in an array or object, like {"name": "Alice",}. JavaScript allows this; JSON does not. It is one of the most common JSON syntax errors because developers used to JavaScript often write it by habit.

Does JSON allow comments? No. JSON has no comment syntax. Adding // or /* */ comments to a JSON file makes it invalid. If you need to add comments to a config file, consider YAML or JSONC instead of plain JSON.

Why does my JSON look correct but still fail validation? Common hidden problems include using smart quotes instead of straight double quotes, copy-pasted non-breaking spaces around keys or values, or a byte order mark at the start of the file. These look visually correct but are rejected by strict parsers.