Conditional Validation in CSV and JSON Schema
I am working on a schema that includes the following fields:
- SEXUAL_ORIENTATION_VALUE_CODE
- SEXUAL_ORIENTATION_VALUE_CODE_DESCRIPTION
- SEXUAL_ORIENTATION_VALUE_CODE_SYSTEM_NAME
- SEXUAL_ORIENTATION_LAST_UPDATED
I need to enforce a condition in the schema such that if the fields SEXUAL_ORIENTATION_VALUE_CODE and SEXUAL_ORIENTATION_VALUE_CODE_DESCRIPTION have values in the CSV file, then the field SEXUAL_ORIENTATION_LAST_UPDATED must also be mandatory.
Could you please guide me on how to achieve this using Frictionless validation? Specifically, I need the schema to enforce this rule during data validation.
Thank you!
It is currently not possible to specify conditional requirements, only atomical ones (not conditional on other fields): see constraints. I think you will need to write your own functions.
Conditional constraints are high on the demand list to be included in the specification though, but not straightforward to add. See https://github.com/frictionlessdata/datapackage/discussions/1058.
Thank you for your response. I’m awaiting further details on the conditions for the other fields.
I’m awaiting further details on the conditions for the other fields.
Can you clarify? What other fields?
For example, if you want to make sure that SEXUAL_ORIENTATION_VALUE_CODE always has a value, use:
[
"name": "SEXUAL_ORIENTATION_VALUE_CODE",
"constraints": {
"required": true
}
]