Pepelen
← Systems Analysis: APIs, Integrations and Data

Lesson

JSON and JSON Schema: the shape of data and its rules

Read a JSON order object, choose types for money, dates and statuses, and describe the object's rules in JSON Schema so that the server validates the request automatically.

1 / 7

JSON: what we send and by what rules

JSON: what we send and by what rules

JSON (RFC 8259) is a text format for data exchange. An object {} holds "key": value pairs; an array [] is a list. Six types: string, number, boolean (true or false), null, object, array. Keys and strings take only double quotes; no comments, no comma after the last element. { "orderId": 9001, "status": "paid", "totalAmount": 17980, "currency": "RUB", "createdAt": "2026-10-19T14:30:00+03:00", "comment": null, "items": [{"productId": 501, "quantity": 2, "price": 8990}] } Romashka's order 9001, status paid, total 179.80: product 501, two at 89.90. The analyst decides: • money: an integer in cents (less often a string "179.80"), the currency in its own field; not a fraction: in binary floating point 0.1 + 0.2 ≠ 0.3; • date and time: an ISO 8601 (RFC 3339) string with a time zone; • status: a string from a fixed list (enum), not a numeric code; • phone and postal code: strings, as a number loses the “+” and leading zeros; • null means “no value”, which is not the same as “no field”. JSON Schema (2020-12, the basis of OpenAPI 3.1) is machine-readable rules for the shape: which fields are required, their types and limits. The server checks requests against them before business logic. The required trap: it only checks that the key exists. "comment": null passes if the type allows null ("type": ["string", "null"]), and an empty string "" passes unless minLength is set.
JSON Schema keywords
KeywordWhat it checksExample
typethe value's type"integer"
requiredwhich keys must be present["storeId", "items"]
enuma value from a list["changed_mind", "other", …]
minimum / maximumthe bounds of a numberlimit from 1 to 100
minLength / maxLength / patternthe length and shape of a stringa phone number matching a pattern
formata well-known string format"date-time"
items / minItemsarray elementsat least one item
additionalPropertieswhether extra fields are allowedfalse — extra fields are forbidden
Romashka's order statuses — enum values
ValueIn plain English
createdCreated
paidPaid
assemblingBeing assembled
in_deliveryIn delivery
deliveredDelivered
cancelledCancelled
Lesson notes
JSON: what we send and by what rules
JSON (RFC 8259) is a text format for data exchange. An object {} holds "key": value pairs; an array [] is a list. Six types: string, number, boolean (true or false), null, object, array. Keys and strings take only double quotes; no comments, no comma after the last element. { "orderId": 9001, "status": "paid", "totalAmount": 17980, "currency": "RUB", "createdAt": "2026-10-19T14:30:00+03:00", "comment": null, "items": [{"productId": 501, "quantity": 2, "price": 8990}] } Romashka's order 9001, status paid, total 179.80: product 501, two at 89.90. The analyst decides: • money: an integer in cents (less often a string "179.80"), the currency in its own field; not a fraction: in binary floating point 0.1 + 0.2 ≠ 0.3; • date and time: an ISO 8601 (RFC 3339) string with a time zone; • status: a string from a fixed list (enum), not a numeric code; • phone and postal code: strings, as a number loses the “+” and leading zeros; • null means “no value”, which is not the same as “no field”. JSON Schema (2020-12, the basis of OpenAPI 3.1) is machine-readable rules for the shape: which fields are required, their types and limits. The server checks requests against them before business logic. The required trap: it only checks that the key exists. "comment": null passes if the type allows null ("type": ["string", "null"]), and an empty string "" passes unless minLength is set.