Choose a control flow
Use control flow when the answer needs more than independent fields: one choice determines another, application facts restrict the available options, or the same decision repeats across a list.
| What you need | Guide |
|---|---|
| Apply a rule when an output field has a particular value | Conditional outputs: if, then and else |
| Restrict a choice using facts supplied by your application | Conditions using state |
| Choose the first matching branch from several cases | Switches |
| Repeat a result structure for each item in a supplied list | For-each loops |
Conditions and switches constrain generated values. State conditions read facts supplied with the request. Loops build one result per supplied item, with its own fields and decisions.
if, then and else are standard JSON Schema keywords. Eligibility rules, switches and loops are Struct extensions under x-runtime; a standard JSON Schema validator alone does not enforce them.
If state is new to you, start with supplying application state. Every guide below also includes a complete, independent example.
These rules shape the answer; they do not execute the actions it names. Your application decides what to do with the returned result.