JSON Schema Basics: Describe and Validate Your JSON

Published 24 November 2026 · 7 min read

JSON itself has no rules about what a document should contain. JSON Schema fills that gap. It is a JSON document that describes the shape of other JSON: which keys exist, what types they hold and which are required. You can use it to check data from an API, to document a format, or to catch a typo before it reaches production.

A small example

Here is a schema for a user record, followed by data it accepts.

{
  "type": "object",
  "properties": {
    "id": { "type": "integer" },
    "email": { "type": "string", "format": "email" },
    "role": { "enum": ["admin", "member"] }
  },
  "required": ["id", "email"]
}

{ "id": 5, "email": "a@example.com", "role": "member" }

The keywords you will use most

  • type: string, number, integer, boolean, object, array or null.
  • properties: the allowed keys of an object, each with its own schema.
  • required: the keys that must be present. Note that properties are optional unless listed here.
  • items: the schema for every element of an array.
  • enum: a fixed list of allowed values.
  • minimum, maximum, minLength, maxLength, pattern: limits for numbers and text.
  • additionalProperties: set to false to reject any key you did not list.
  • format: a hint such as email, date, date-time or uri.

Things that surprise people

  • Extra keys are allowed by default. A typo in a key name passes unless you set additionalProperties to false.
  • Integer is stricter than number. The value 3 is valid for both, and 3.5 only for number.
  • Format may not be enforced. Many validators treat format as an annotation unless you turn checking on.
  • null is its own type. A key that may be null needs both types, for example ["string", "null"].
  • Drafts differ. Draft-07, 2019-09 and 2020-12 are in use, and a few keywords changed between them. State the draft in $schema.

Reading a validation error

A good error tells you two things: the path to the bad value, such as /items/2/price, and the rule it broke, such as expected number but found string. Find the path first, and the cause is usually obvious.

Do not write it all by hand

A sample document is a good starting point. The JSON Schema generator and validator infers types, required keys, formats and array items from your JSON, and you then tighten the result by hand. It can also validate data against a schema and list every error with its path. It runs in your browser, so your data stays on your device. If your JSON will not parse at all, see unexpected token in JSON.