Skip to content
Advertisement

Using dynamic object name in YAML scheme

I want to validate YAML files in Python with my own scheme. A valid YAML shall look like this:

JavaScript

While [windows, other] are dynamic, any name shall allowed there (i.e. “solaris”, “mac”, “templeOS”)

I’m using validate from jsonschema like described here: Validating a yaml document in python

Any other module where this works would be also okay.

Advertisement

Answer

You’re searching for additionalProperties:

JavaScript

Setting it to false disallows unknown properties in the root mapping. Since JSON Schema is for JSON, keys will always be strings and you can set only the value type for additional properties.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement