← 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.
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
| Keyword | What it checks | Example |
|---|---|---|
| type | the value's type | "integer" |
| required | which keys must be present | ["storeId", "items"] |
| enum | a value from a list | ["changed_mind", "other", …] |
| minimum / maximum | the bounds of a number | limit from 1 to 100 |
| minLength / maxLength / pattern | the length and shape of a string | a phone number matching a pattern |
| format | a well-known string format | "date-time" |
| items / minItems | array elements | at least one item |
| additionalProperties | whether extra fields are allowed | false — extra fields are forbidden |
Romashka's order statuses — enum values
| Value | In plain English |
|---|---|
| created | Created |
| paid | Paid |
| assembling | Being assembled |
| in_delivery | In delivery |
| delivered | Delivered |
| cancelled | Cancelled |
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.