[Python] How to validate a list of dictionaries using jsonschema with Python

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página