Python 用于查看的模块/ JSON 模式文件
Python module for viewing/ JSON Schema files
我正在寻找一个 Python 模块来加载 JSON 架构文件并将其作为对象处理。我可以通过常规 json
模块来做到这一点,例如dictor
,但我希望找到一个 JSON 架构特定模块,例如自然理解 dependencies
、definitions
和类似概念,提供更轻松的数据处理。
明确地说,我不是在寻找 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.
您可以找到 JSON 个架构编辑器 here 的列表。在同一页面上有一个应用程序列表,可以将模式转换为 class 定义,反之亦然。
为此我最终使用了 sphinx-jsonschema
。
我正在寻找一个 Python 模块来加载 JSON 架构文件并将其作为对象处理。我可以通过常规 json
模块来做到这一点,例如dictor
,但我希望找到一个 JSON 架构特定模块,例如自然理解 dependencies
、definitions
和类似概念,提供更轻松的数据处理。
明确地说,我不是在寻找 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.
您可以找到 JSON 个架构编辑器 here 的列表。在同一页面上有一个应用程序列表,可以将模式转换为 class 定义,反之亦然。
为此我最终使用了 sphinx-jsonschema
。