1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Difference in validation result using `jsonschema` and `check-jsonschema` in regard...

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024 às 17:42.

  1. Stack

    Stack Membro Participativo

    Given model_schema.json

    {
    "properties": {
    "dt": {
    "format": "date-time",
    "title": "Dt",
    "type": "string"
    }
    },
    "required": [
    "dt"
    ],
    "title": "Model",
    "type": "object",
    "$schema": "https://json-schema.org/draft/2020-12/schema"
    }


    and model_instance.json

    {
    "dt": "2032-04-23T10:20:30"
    }


    Running the following Python script produces no error.

    import json
    from pprint import pprint

    import jsonschema


    with open("model_schema.json") as f:
    schema = json.load(f)

    with open("model_instance.json") as f:
    m1_as_dict = json.load(f)


    pprint(schema)
    print("\n=====================================\n")
    pprint(m1_as_dict)


    jsonschema.validate(m1_as_dict, schema)


    However, running the the following command

    check-jsonschema --schemafile model_schema.json model_instance.json


    produces the following error

    Schema validation errors were encountered.
    model_instance.json::$.dt: '2032-04-23T10:20:30' is not a 'date-time'


    I think the command's behavior is correct. Why doesn't the given Python script produce a comparable error as the command?

    My environment is:

    check-jsonschema 0.28.2
    jsonschema 4.21.1
    jsonschema-specifications 2023.12.1
    types-jsonschema 4.21.0.20240331

    Continue reading...

Compartilhe esta Página