Guides · Structure & safety

JSON Schema basics

Valid JSON only means the syntax parsed. Schema is how you write down “amount is a number and order_id is required.”

A minimal schema

{
  "type": "object",
  "required": ["code", "data"],
  "properties": {
    "code": { "type": "integer" },
    "data": {
      "type": "object",
      "required": ["order_id", "amount"],
      "properties": {
        "order_id": { "type": "string" },
        "amount": { "type": "number" }
      }
    }
  }
}

Use ["string", "null"] when the API sends null. Lock a draft version in the repo. Validate with AJV or Python’s jsonschema; use HiJSON to inspect a failing instance.