tools / json / jmespath / validate json against a schema
json query · jmespath

Validate JSON against a schema

JSON Schema is the standard for declaring the shape of JSON data. Validators check that incoming data matches your schema before you trust it — catches typos, missing fields, type errors before they reach your business logic.

intermediate jmespath / aws cli

The query

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["id", "email"],
  "properties": {
    "id": {"type": "integer", "minimum": 1},
    "email": {"type": "string", "format": "email"},
    "role": {"enum": ["admin", "user", "guest"]}
  },
  "additionalProperties": false
}

Pass / fail

InputResult
{"id": 1, "email": "a@b.com"}passes
{"id": 42, "email": "x@y.io", "role": "admin"}passes
{"id": 0, "email": "a@b.com"} (id violates minimum:1)fails
{"id": 1, "email": "not-an-email"} (format violation)fails
{"id": 1, "email": "a@b.com", "extra": 1} (additionalProperties:false)fails

Edge cases & caveats

Without `additionalProperties: false`, extra fields PASS validation. Always set explicitly. `format: email` is advisory in draft 2020-12 — set `"strict": true` or use draft 7 for hard enforcement.

Common use cases

Run JMESPath against piped JSON
jsonyo is the CLI twin of the jsonyo browser extension — validate against schemas, format, run JMESPath queries against piped JSON. Zero deps.
Open jsonyo  

Related

extract values from nested arrays · jmespath vs jq: which json query language? · pretty-print json (formatted output) · chain expressions with pipes · ↗ return 422 on JSON Schema fail