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).

POSThttps://apibox.io.vn/v1/json-validator

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

NameInTypeRequiredDefault
jsonbodystringyesThe JSON document to check: a JSON string, or any JSON value. A raw text/plain body is also accepted.
schemabodyobjectnoJSON Schema (object or JSON string). Without it only the syntax is checked.
draftbody|querystringno2020-12Schema 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}}}}'

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

Start with 1,000 free requests every month. Get free API key →