Skip to content
BENIBIX Learn

JSON Schema

Development📄 Files & FormatsData Formats

Also known as JSON Schema Validation, JSON Schema File

JSON that describes what other JSON should look like. Tools use it to check data.

Think of it like

Think of it like a form with rules. The name box must be filled, and the age box must be a number.

Example

A shop's API checks each order against its schema. An order with the price written as the word ten is turned away with a clear error.

Why it matters

It catches bad data at the door. That stops it before it breaks something deep in the program.

Definition

JSON Schema is a way to describe what good JSON looks like. The schema is written in JSON too. It lists the fields, their types and which ones are required. A tool can then check any JSON against it and point to each mistake. The current version is called 2020-12. Many APIs and code editors use it to catch bad data early.

Example code

json
{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer", "minimum": 0 }
  },
  "required": ["name"]
}
The name must be there and be text. The age, if given, is a whole number of zero or more.
The note at the bottom: a schema checks the JSON text before the next program trusts it.

Common mistake

Leaving out the required list. Without it, every field is optional, so an empty object passes the check.

Key takeaways

  1. 1
    Describes the shape. It lists fields and their types.
  2. 2
    Written in JSON. The rules use the same format.
  3. 3
    Checks data. Tools flag every mismatch.

Learn it properly