Validation Rules
These rules must be followed when authoring a survey schema to ensure the form works correctly.
Unique Field Keys
Every key in the fields array must be unique across the entire survey, and so must every sub_key. Duplicate keys will cause unpredictable behavior in conditional logic and data export.
// Correct — all keys are unique
{ "key": "full_name" }
{ "key": "age" }
{ "key": "email" }
// Incorrect — duplicate key
{ "key": "full_name" }
{ "key": "full_name" } // ❌ duplicateRegex Escaping
When using regular expressions in JSON, backslashes must be double-escaped. A single \ in a regex pattern becomes \\ in the JSON string.
| Regex Pattern | JSON Value |
|---|---|
\d | "\\d" |
\s | "\\s" |
\+ | "\\+" |
// Phone number — double-escaped backslashes
"regex": "^\\+?[1-9]\\d{1,14}$"
// Email address
"regex": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"Array Defaults
The default_value property must always be an array, even when only a single value is pre-selected.
// Correct
"default_value": ["MALE"]
// Incorrect
"default_value": "MALE" // ❌ must be an arrayConditional Key Matching
Keys referenced in conditionals must exactly match the key values defined in the fields array. Mismatched casing or typos will cause the logic to silently fail.
"fields": [
{ "key": "type_of_house", ... }
],
"conditionals": {
"1": "type_of_house == 'APARTMENT' >> room_count" // ✅ matches exactly
}Values compared against a choice field must match one of its choices exactly. A value that isn't a choice can never match, so the rule never fires.
"choices": ["Owner-occupied", "Fully rented out", "Mixed (owner + tenants)"]
"1": "tenancy_status == 'Owner-occupied' >> estimated_annual_rent" // ✅ a listed choice
"2": "tenancy_status == 'Vacant / unoccupied' >> estimated_annual_rent" // ❌ not a choiceSection References
When a survey defines sections, each field's section must match a section id exactly.
"sections": [{ "id": "section_owner", "label": "Owner Information" }],
"fields": [
{ "key": "owner_name", "section": "section_owner", ... }, // ✅
{ "key": "owner_phone", "section": "owner", ... } // ❌ no section with id "owner"
]Grouped Choices
When choices is an object:
- Every group must contain either an array with at least one option or another object of groups.
- Every branch must have the same number of levels, and the last level must be an array of options.
- The field must have a
sub_key: a string for two levels, or an array with one key per level below the top for three or more. - No key in
sub_keymay clash with any otherkeyorsub_key. - Option text can repeat across groups (e.g.
"Other"), but group names within the same group must be unique.
// ❌ The Niger branch has three levels, but the Lagos branch has four
"choices": {
"North Central": { "Niger": ["Minna"] },
"South West": { "Lagos": { "Ikeja": ["Alausa"] } }
}TIP
The Survey Builder checks all of these rules as you edit and lists any problems under the affected field or rule.