How to Validate JSON and Check for Errors
To validate JSON, check whether the complete input follows standard JSON syntax. A validator can find missing commas, trailing commas, missing quotes, single quotes, incorrect brackets, unsupported values, and broken escaping.
By Archana Bhandari ·
A quick validation example
VALID JSON:
{
"name": "Rahul",
"city": "Dehradun"
}An invalid JSON example
INVALID JSON: the trailing comma after the final property makes this invalid standard JSON. Already have JSON you want to check? Paste it into JSONPlease JSON Validator to see whether it is valid. The check runs locally in your browser.
{
"name": "Rahul",
"city": "Dehradun",
}What does JSON validation mean?
Basic JSON validation checks whether text follows JSON syntax rules. Valid JSON can be parsed correctly; invalid JSON cannot. INVALID JSON below is missing a comma between its properties.
{
"product": "Wireless Mouse"
"price": 799
}How to validate JSON online
Open JSONPlease JSON Validator, paste or type JSON, then choose Validate. The validation report shows the result; when there is a syntax problem, it provides available exact line and column details and marks the editor. You can also open a .json file directly. Correct the JSON and validate again.
What makes JSON valid?
Property names and string values must use double quotes. Properties need commas between them, but no trailing comma after the final property or array item. Objects use { }, arrays use [ ], and all brackets must match. Strings must escape special characters correctly. Standard JSON does not support comments.
- VALID: { "name": "Rahul" } — INVALID: { name: "Rahul" }.
- VALID: { "city": "Dehradun" } — INVALID: { "city": 'Dehradun' }.
- VALID: { "items": [1, 2] } — INVALID: { "items": [1, 2,] }.
JSON data types that are valid
JSON supports strings, numbers, objects, arrays, booleans, and null. JavaScript values such as undefined, NaN, and Infinity are not part of standard JSON.
{
"name": "Rahul",
"age": 28,
"active": true,
"skills": ["PHP", "JavaScript"],
"address": { "city": "Dehradun" },
"middleName": null
}Common JSON validation errors
The common errors are trailing or missing commas, single quotes, unquoted property names, missing closing brackets, comments, invalid escape sequences, and unsupported values such as undefined. A validator points to the syntax issue; a repair tool may help with common malformed input, but it cannot guarantee every correction.
How to check JSON manually
For a small document, inspect quotes, commas, brackets, data types, escaping, and any extra text before or after the JSON. For large or deeply nested JSON, a validator is much easier and avoids manual counting mistakes.
- Check double quotes around keys and text values.
- Match every opening { or [ with the right closing character.
- Look for missing or trailing commas.
- Check for comments, undefined, or stray text.
How to validate a JSON file
A .json file contains JSON text, for example config.json. You can open it in the JSONPlease Validator or copy its contents into the editor, then select Validate.
{
"theme": "dark",
"notifications": true
}How to validate an API JSON response
When troubleshooting an API, inspect and validate the actual response rather than only the JSON you expected. The response below is valid JSON. If the response starts with <!DOCTYPE html>, it is HTML rather than JSON, often because of an incorrect endpoint, a 404 or server error, or an authentication or access-denied page.
{
"status": "success",
"userId": 101
}Valid JSON vs correct data
Syntactically valid JSON is not automatically correct for an application. This is valid JSON, but its values may fail an application's business rules. Syntax validation asks, “Is this JSON valid?” Application or schema validation asks, “Does this data have the fields and values my application expects?”
{
"email": "not-an-email",
"age": -500
}JSON validation vs JSON Schema validation
Basic validation checks syntax. JSON Schema validation can also check expected structure, types, required properties, and other constraints. For example, { "age": "twenty" } is valid JSON syntax, but a schema may require age to be a number.
JSON Validator vs JSON Formatter
A validator checks syntax. A formatter makes JSON easier to read. The minified JSON below is already valid; formatting changes its presentation, not its validity.
{"name":"Rahul","city":"Dehradun"}JSON Validator vs JSON Repair
Use Validator to check and report whether JSON is valid. Use Repair when input has common fixable malformed syntax. Then validate the repaired result and format it if readability is needed. The practical flow is: Check → Validator; broken input → Repair; readable output → Formatter.
Does formatting JSON make it valid?
No. Formatting and validation are different. Adding indentation does not remove the trailing comma in this INVALID JSON, so it remains invalid until the syntax is corrected.
{
"name": "Rahul",
}Can JSON be valid without an object or array?
Yes. A JSON document can be a top-level string, number, boolean, or null, as well as an object or array. A particular API or application may still require an object or array for its own purposes.
Valid top-level JSON values:
"Rahul"
42
true
nullHow to validate JSON before using it
Obtain or create the JSON, format it if readability helps, validate its syntax, fix or repair errors, validate again, then check the structure or schema if the application has specific requirements. Finally, test it in the target application.
Quick JSON validation checklist
Check the complete input, not only a fragment.
- Are property names and strings in double quotes?
- Are properties separated by commas without a trailing comma?
- Do all { } and [ ] brackets match?
- Are special characters escaped correctly?
- Are undefined, comments, or extra text present?
- Does the complete input pass a JSON validator?
Frequently asked questions
What does it mean to validate JSON? It means checking whether text follows JSON syntax rules.
How do I check if JSON is valid? Paste the complete input into a JSON validator.
What makes JSON invalid? Common causes are incorrect quotes, commas, brackets, escaping, comments, and unsupported values.
Can JSON use single quotes? No. Standard JSON uses double quotes.
Are trailing commas allowed? No.
Can JSON contain comments? No.
Is undefined valid JSON? No.
Does valid JSON mean the data is correct? No; it may still fail application rules.
What is the difference between syntax and JSON Schema validation? Schema validation also checks expected structure, types, and required properties.
Can a validator fix JSON automatically? A validator checks and reports; use a repair tool for common malformed input.
How do I validate a JSON API response? Inspect the complete actual response, then validate it if it is JSON.