Is multiple "if" "then" valid in JSON schema? #503
Replies: 1 comment
-
|
You can't have multiple {
"if": {...},
"then": {...},
"if": {...},
"then": {...}
}In JSON Schema, you can combine schemas with the {
"allOf": [
{
"if": {...},
"then": {...}
},
{
"if": {...},
"then": {...}
}
]
}Putting each Another thing to look out for is to make sure you're putting the Finally, the "domainFields" schema doesn't look right. I think you're trying to do something more like this, {
"type": "array",
"items": {
"anyOf": [
{
"type": "object",
"properties": { ... number domain field properties ... }
},
{
"type": "object",
"properties": { ... text domain field properties ... }
},
{
"type": "object",
"properties": { ... date domain field properties ... }
}
]
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to create a JSON schema where I have multiple subschema that should populate conditionally and each of them are unrelated
{ "type":"object", "properties":{ "eventName":{ "type":"string" }, "occured":{ "type":"boolean", "enum":[ "true", "false" ], "description":"select false for negative sentences. Example: 'Customer didn't purchase the bundle' means purchase_bundle event does not occured so select false" }, "if":{ "properties":{ "occured":{ "const":"true" } } }, "then":{ "properties":{ "frequency":{ "type":"object", "properties":{ "frequency_count":{ "type":"string", "oneOf":[ { "name":"At least once", "description":"select this option by default if number of occurence is not mentioned in user input. Example: 'user purchased bundle'" }, { "name":"Specific number of times", "description":"select this option if number of occurence is mentioned in user input. Example: 'user purchased bundle 5 times'" } ] }, "occurence_count_condition":{ "type":"string", "enum":[ "is", "is btw", "is gt", "is lt" ], "description":"only populate if 'Specific number of times' is selected as 'frequency_count'. select one of the option according to user input" }, "occurence_count":{ "type":"string", "description":"Enter a value for number of occurence from user input" } } } } }, "drillDown":{ "type":"boolean", "enum":[ "true", "false" ], "description":"Select 'true' only if domain_field information is given in user input. Select 'false' otherwise. Example: 'purchased bundle name any of 4000_opt2_on' here bundle name is the domain_field. Do NOT confuse with campaign information as domain_field information. Example: 'The users were not included in any control group participation for the last 6 days and the UK non-roamers campaign.' here UK non-roamers is a campaign info NOT domain_field" }, "if":{ "properties":{ "drillDown":{ "enum":[ "true" ] } }, "required":[ "drillDown" ] }, "then":{ "required":[ "domainFields" ] }, "else":false, "domainFields":{ "type":"array", "description":"populate only if 'drillDown' option is true", "anyOf":[ { "number_domain_field_name":{ "type":"string", "description":"name of the domain field mentioned in user input if domain field type is of number" }, "condition":{ "enum":[ "is any of", "is between", "is greater than", "is greater than or equal to", "is less than", "is less than or equal to", "is not any of" ] }, "number_domain_field_value":{ "type":"string", "description":"value of the domain field mentioned in user input if domain field type is of number" } }, { "text_domain_field_name":{ "type":"string", "description":"name of domain field mentioned in user input if domain field type is of text" }, "condition":{ "enum":[ "contains", "equals", "is any of", "is not any of", "starts with" ] }, "text_domain_field_value":{ "type":"string", "description":"name of the domain field mentioned in user input if domain field type is of text" } }, { "date_domain_field_name":{ "type":"string", "description":"name of domain field mentioned in user input if domain field type is of date" }, "condition":{ "enum":[ "is on", "is after", "is before", "is between" ] }, "date_domain_field_value":{ "type":"string", "description":"value of the domain field mentioned in user input if domain field type is of date" } } ] }, "cam_eng_program_details":{ "type":"object", "description":"Do NOT populate if campaign, engagement or program informations are not mentioned in user input.", "properties":{ "with_reference_to":{ "type":"string", "enum":[ "campaign", "engagement", "program" ] }, "campaign_category":{ "type":"string", "default":"Any campaign category" }, "campaign":{ "type":"string", "default":"Any campaigns" }, "applications":{ "type":"string", "default":"Any applications" } }, "required": ["with_reference_to", "campaign_category", "campaign", "applications"] }, "recency":{ "type":"object", "properties":{ "eventDateTime":{ "type":"string", "oneOf":[ { "name":"All events after", "description":"Retrieve all events occurring after a specified point in time. example: 'for the last 6 days' means events after specified time for 6 days" }, { "name":"All events before", "description":"Retrieve all events occurring before a specified point in time." }, { "name":"All events between", "description":"Retrieve all events occurring between two specified points in time." }, { "name":"All events on", "description":"Retrieve all events occurring on a specific point in time." } ], "description":"Specifies the type of temporal filter for the events." }, "timeDefinition":{ "type":"string", "oneof":[ { "name":"this date and time", "description":"Specify a specific date and time. Only populate if a specific date and time is mentioned. Example: 'Fri Oct 20 2023 10:35:27 in In indian timezone'" }, { "name":"now (target time)", "description":"Refer to the current date and time as the broadcast target time." }, { "name":"today (start of)", "description":"Refer to the start of the current day." }, { "name":"yesterday (start of)", "description":"Refer to the start of the previous day." }, { "name":"tomorrow (start of)", "description":"Refer to the start of the next day." }, { "name":"now +/- days/weeks/months/years", "description":"Refer to the current date and time with an offset in days, weeks, months, or years. select when an offset is specified in input. Example for offset: '6 days ago'" }, { "name":"now +/- hours/minutes/seconds", "description":"Refer to the current date and time with an offset in hours, minutes, or seconds." }, { "name":"weekday +/- weeks", "description":"Refer to a specific weekday with an offset in weeks." }, { "name":"day of month", "description":"Refer to a specific day of the month." } ], "description":"select an option for time specification" }, "number_of_days_week_month_year":{ "type":"integer", "description":"enter number of days/weeks/months/years as an offset from 'now +/- days/weeks/months/years'" }, "days_weeks_months_years":{ "type":"string", "enum":[ "days", "weeks", "months", "years" ], "description":"Select a time unit to specify an offset." }, "specified_time_point":{ "type":"string", "enum":[ "ago", "from today" ], "description":"select ago to indicate a time interval in the past, e.g., '2 days ago.' and 'from today' refer to a time interval from the current date onward, should populate when 'timeDefinition' is 'now +/- days/weeks/months/years'" }, "targetOrSpecifiedTime":{ "type":"string", "oneOf":[ { "name":"at specified time", "description":"select this if the action to be executed at a time specified in the user-input. Example: 'The users were not included in any control group participation for the last 6 days and the Voice+DataDropper campaign'" }, { "name":"at target time", "description":"select this if the action to be executed at the broadcast target time, do not select this option if broadcast information is not specified in the user-input. Example: 'at target time of the broadcast_name' in the user input" } ] }, "time":{ "type":"string", "description":"Enter the time specified in prompt in HH:mm:ss format and only populate if 'at specified time' is selected and enter 00:00:00 by default if no time is not mentioned in user input" } }, "if":{ "properties":{ "timeDefinition":{ "enum":[ "now +/- days/weeks/months/years" ] } }, "required":[ "timeDefinition" ] }, "then":{ "required":[ "number_of_days_week_month_year", "days_weeks_months_years", "specified_time_point", "targetOrSpecifiedTime" ] }, "else":false, "if":{ "properties":{ "targetOrSpecifiedTime":{ "enum":[ "at specified time" ] } }, "required":[ "targetOrSpecifiedTime" ] }, "then":{ "required":[ "time" ] }, "else":false, "required":[ "eventDateTime" ] } }, "required":[ "eventName", "occured", "recency", "drillDown" ] }Example: Only populate "frequency" if "occurred" is true and only populate "domainFields" if "drillDown" is true
(Edit: Added code block for readability.)
Beta Was this translation helpful? Give feedback.
All reactions