JSON Validator API
Check JSON syntax with exact line and column of errors, and validate data against a JSON Schema (draft 4, 7, 2019-09 or 2020-12).
Send the document to check in json, either as a JSON string (so syntax errors can be reported) or as an already-parsed value. If it is not valid JSON, the response has valid_json: false and a parse_error with the message, character position, line and column. A raw text/plain body is also accepted as json.
Add a schema (object or JSON string) to validate the data against a JSON Schema. The default dialect is 2020-12; set draft to 4, 7 or 2019-09 for older schemas. Each error has the instance path (e.g. /age), the failing keyword, the schema_path and a readable message; up to 200 errors are returned. Without a schema, only the syntax is checked.
The request body is limited to 5 MB. An invalid schema returns a 400 error with code invalid_schema.
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
json | body | string | yes | The JSON document to check: a JSON string, or any JSON value. A raw text/plain body is also accepted. | |
schema | body | object | no | JSON Schema (object or JSON string). Without it only the syntax is checked. | |
draft | body|query | string | no | 2020-12 | Schema dialect: 4, 7, 2019-09 or 2020-12. |
Example
curl -X POST "https://apibox.io.vn/v1/json-validator" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"json":"{\"name\":\"Alice\",\"age\":-3}","schema":{"type":"object","required":["name","email"],"properties":{"name":{"type":"string"},"age":{"type":"integer","minimum":0}}}}'const res = await fetch('https://apibox.io.vn/v1/json-validator', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"json": "{\"name\":\"Alice\",\"age\":-3}",
"schema": {
"type": "object",
"required": [
"name",
"email"
],
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer",
"minimum": 0
}
}
}
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/json-validator",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"json": "{\"name\":\"Alice\",\"age\":-3}", "schema": {"type": "object", "required": ["name", "email"], "properties": {"name": {"type": "string"}, "age": {"type": "integer", "minimum": 0}}}},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/json-validator');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"json":"{\\"name\\":\\"Alice\\",\\"age\\":-3}","schema":{"type":"object","required":["name","email"],"properties":{"name":{"type":"string"},"age":{"type":"integer","minimum":0}}}}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"valid": false,
"valid_json": true,
"draft": "2020-12",
"error_count": 2,
"errors": [
{
"path": "/",
"keyword": "required",
"schema_path": "#/required",
"message": "Instance does not have required property \"email\"."
},
{
"path": "/age",
"keyword": "minimum",
"schema_path": "#/properties/age/minimum",
"message": "-3 is less than 0."
}
]
}
Use cases
- Validate API request payloads or webhooks against a schema
- Check configuration files in CI before deploying
- Find the exact line and column of a JSON syntax error
- Test JSON Schemas while writing an API specification
FAQ
Which JSON Schema drafts are supported?
Draft 4, draft 7, 2019-09 and 2020-12 (default). Choose with the draft parameter.
How do I get the line number of a JSON syntax error?
Send the document as a string in json. When parsing fails, parse_error contains position, line and column when the parser reports them.
Can I validate syntax without a schema?
Yes. Omit schema; the response then only says whether the JSON is valid, with a note that no schema was given.
Related APIs
JSON Formatter
Pretty print JSON with 0-8 spaces or tabs, minify it, or sort object keys recursively. Syntax errors are reported with line and column.
CSVCSV to JSON
Convert CSV into an array of JSON objects using the header row, with delimiter auto-detection, number and boolean typing, and row-level errors.
J→CJSON to CSV
Convert a JSON array of objects or arrays into CSV with a header row and a custom delimiter, returned as JSON or as a downloadable text/csv file.