Validate JSON data with schemas, types, required fields, formats, composition, and API contracts.
Lessons
Validate string format with regular expressions.
Pattern (Regex) is easiest to learn by reading the example, changing it, and observing the result.
{
"type": "object",
"properties": {
"slug": {
"type": "string",
"pattern": "^[a-z0-9-]+$"
},
"zip": {
"type": "string",
"pattern": "^\\d{5}(-\\d{4})?$"
}
}
}Practice the Pattern (Regex) example in a small scratch file, then explain what changed and why.