framework icon indicating copy to clipboard operation
framework copied to clipboard

Conditional Validation in CSV and JSON Schema

Open megin1989 opened this issue 1 year ago • 3 comments

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!

megin1989 avatar Jan 15 '25 07:01 megin1989

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.

peterdesmet avatar Jan 24 '25 15:01 peterdesmet

Thank you for your response. I’m awaiting further details on the conditions for the other fields.

megin1989 avatar Jan 27 '25 04:01 megin1989

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
  }
]

peterdesmet avatar Jan 29 '25 15:01 peterdesmet