A JSON validator is one of the simplest tools in a developer's workflow — but most developers only reach for it when something is already broken. Building validation into your routine at the right points stops problems before they reach users. These six practices will keep invalid JSON out of your APIs, config files, and databases.
1. Validate before you send, not after it fails
The most common mistake is treating validation as a debugging step instead of a prevention step. If you paste JSON into a validator only after seeing a parse error in your app, you have already wasted time tracing down where the problem lives.
The better habit: validate JSON before it leaves your hands. When you write a config file, edit an API payload, or copy JSON from a response — run it through a validator first. The cost is ten seconds. The cost of skipping it is finding the bug three layers deeper in the call stack.
2. Read the error message, not just the line number
A good validator tells you two things: where the error is and what the error is. Most developers look at the line number and jump straight to the file. The error message itself is usually more useful.
Common validator outputs and what they mean:
- "Unexpected token }" — The parser hit a closing brace before it expected one. Usually means a missing comma or a stray brace somewhere earlier.
- "Expected ',' or '}'" — You are missing a comma between two properties.
- "Unexpected end of JSON input" — A bracket or brace was opened and never closed. Often happens with deeply nested objects.
- "Unexpected token '" — Single quotes are used instead of double quotes somewhere.
When you understand what the parser expected vs. what it found, you can usually fix the error without even looking at the line number.
3. Always use double quotes — consistently
JSON requires double quotes for all string keys and string values. This is non-negotiable. But the subtler issue is inconsistency during manual editing: switching between an IDE that auto-completes with double quotes and a terminal or text editor that doesn't.
// Will parse successfully
{ "status": "active", "count": 12 }
// Will fail — single-quoted key
{ 'status': "active", "count": 12 }
// Will fail — unquoted key (valid JavaScript, invalid JSON)
{ status: "active", "count": 12 }
If your team generates JSON programmatically, this is not an issue — JSON.stringify() always outputs double-quoted keys. The risk is hand-edited JSON: config files, test fixtures, documentation examples.
4. Validate sections when debugging large payloads
When you have a large JSON response — thousands of lines, deeply nested — pasting the entire blob into a validator gives you one error at a time. If the first error is on line 847 and fixing it reveals another error, you can spend a long time iterating.
A faster approach: isolate the section you suspect and validate that subsection first. Most validators accept any valid JSON value, not just objects — so you can paste a single array or nested object out of context and validate it independently.
// Instead of validating this entire payload at once:
{
"metadata": { ... },
"results": [ ... 800 items ... ],
"pagination": { ... }
}
// Pull out the section you're editing and validate it:
{
"page": 1,
"total": 824,
"per_page": 20
}
5. Know the difference between syntax validation and schema validation
Syntax validation checks structure: are the quotes, commas, and brackets correct? Schema validation checks content: is the data the right shape for your application?
A JSON document can be syntactically valid but semantically wrong for your use case:
// Syntactically valid — passes any JSON validator
{
"user_id": "abc123",
"age": "twenty-eight"
}
// Semantically invalid — age should be a number, not a string
// A JSON Schema validator would catch this
For production APIs, syntax validation catches typos. Schema validation (using JSON Schema) catches data contract violations — wrong types, missing required fields, values outside allowed ranges. Both matter, and they are different tools for different problems.
6. Add validation to your CI pipeline
For projects that include JSON files — config files, translation files, API fixtures, test data — add a validation step to your CI pipeline. Many CI tools support this natively. For a simple check, python -m json.tool yourfile.json returns a non-zero exit code if the file is invalid JSON, which is enough to block a broken merge.
This removes the human from the loop entirely. No one has to remember to validate; the pipeline enforces it automatically.
FAQ
What is the difference between syntax validation and schema validation?
Syntax validation checks whether JSON is structurally valid — correct quotes, commas, and brackets. Schema validation checks whether the data matches an expected structure, such as required fields and correct value types.
Should I validate JSON in development or only before deployment?
Both. Validate during development to catch errors early. Validate in CI pipelines to block broken JSON from reaching production automatically.
Validate JSON instantly
Paste your JSON and get the exact error location — line number, character position, and what the parser expected. Free, private, no signup required.
Open JSON Validator