'How to validate a list of dictionaries using jsonschema with Python

I have a list of dictionaries like this:

list_of_dictionaries = [{'key1': True}, {'key2': 0.2}]

And I want to validate it using jsonschema package.

I created a schema like this:

schema = {
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "key1": {
                "type": "boolean"
            },
            "key2": {
                "type": "number"
            }
        },
        "required": ["enabled"]
    }
}

But it is not correct for my list because to make it works my list should be like this:

list_dict = [{'key1': True, 'key2': 0.5}]

How can I create a correct schema to validate my list? Thank you in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source