从jsonschemas创建严格的模式
strictyamljsonschema的Python项目详细描述
严格的方案
将json模式转换为strictyaml模式。
简单示例:
{"type":"object","properties":{"age":{"type":"integer"},"name":{"type":"string"},"possessions":{"type":"array","items":{"type":"string"}}},"required":["age","name","possession"]}
# All about the charactername:Ford Prefectage:42possessions:-Towel
fromstrictyamljsonschemaimportload_schemafromstrictyamlimportloadimportjson
正确解析:
print(load(yaml_snippet,load_schema(json.loads(json_schema))).data)
OrderedDict([('name', 'Ford Prefect'), ('age', 42), ('possessions', ['Towel'])])
安装
$ pip install strictyamljsonschema