用于查看/JSON模式文件的Python模块

2024-06-26 13:53:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在寻找一个Python模块,用于加载JSON模式文件并将其作为对象处理。我可以通过常规的json模块和dictor来实现这一点,但我希望找到一个特定于JSON模式的模块,该模块可以本地理解dependenciesdefinitions和类似的概念,提供更简单的数据处理

明确地说,我不是在寻找JSON模式验证工具,而是一个JSON模式对象管理器。这样的东西存在吗

要说明我希望执行的处理类型,请参见以下内容:

def schema_lister(device,schema, path):
    path_conf = Path(__file__).resolve().parent.parent
    schema_dir = f"_static/tmp/{device}_schema.json"
    path_schema = Path(path_conf,schema_dir)

    with open(path_schema) as json_file:
        schema_json = json.load(json_file)
        json_file.close()

    schema = dictor(schema_json,path)

    for elm in schema:
        elm_schema = dictor(schema,elm)
        if elm != 'anyOf' and elm != 'dependencies' and isinstance(elm_schema, dict):
            # do things, e.g. print title, description etc.


Tags: 模块path对象jsonschemadeviceconf模式