Default Values

If a key (within a dictionary) is missing and the data schema defined a default value for this key, validation can be instructed to add this key with the default value to the data.

Code Example

import yaml
import nadap

schema_definition_yaml = """
root:
  type: dict
  keys:
    no_conversion: int
    convert_type:
      type: int
      convert_to: str
    replace_empty:
      type: list
      replace_empty_to: ""
"""

n = nadap.Nadap()
schema_def = yaml.load(schema_definition_yaml, Loader=yaml.SafeLoader)
n.schema = schema_def

converted_data = n.validate({"no_conversion": 1, "convert_type": 2, "replace_empty": []}, flags=nadap.CONVERT_DATA)

print(yaml.dump(converted_data))

... will print this output:

default: 0