Validate JSON online
Use this free JSON validator to check whether the syntax of your JSON is valid:
Validating JSON syntax or structure
There are two levels on which you can validate your JSON documents:
- Validate the syntax of a JSON document
- Validate the structure of a JSON document against a schema
In general, these two categories are both called “validating JSON”, which can be confusing. We’ll clarify them here.
Validate JSON syntax
Validating the syntax makes sure the JSON document contains valid JSON and can be parsed. For example, forgetting a comma between two items in an array makes the JSON invalid. Trying to parse the document will result in a syntax error. For example the following document is invalid because it misses a comma between the first and the second key-value pair:
{
"name": "Joe"
"age": 42
}
{
“Name”: “Joe”,
“age”: 42
}
Validate JSON structure
Besides syntax errors, it can be that you want to verify whether the contents of a document is according to a specific data structure or a “schema”. For example, given the following document:
{
"name": "Joe",
"age": 42
}
{
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
},
"required": [ "name", "age" ]
}
When to validate JSON?
You may need to manually validate a JSON document when you’re debugging an issue in your code as a developer. In such a case you can use online tools like JSON Editor Online.
When you need to programmatically validate JSON, this is normally best to do “at the gate”: when the data enters your application. For example when fetching data in a web application, or receiving JSON in a backend server via a REST API. Best is to directly check the data, so you don’t have to reckon with potentially invalid data in the application itself.
Is Json Valid conclusion
So, what makes a JSON valid? We have learned that we can look at two things. The first is validating the syntax of a JSON document, like missing quotes or commas. The second is validating the structure of a JSON document, such as verifying that the document is an object containing properties like “name” and “age”.
Validation of these two categories requires different tools. Validating JSON syntax requires a strict JSON parser with helpful error messages, else debugging an issue can be difficult. A tool like JSON Editor Online (and the inline editor in this article) can help repair syntax errors automatically. Validating JSON structure requires a validation library, such as Ajv with JSON Schema.