简体   繁体   中英

How to generate json schema from python dict

I am looking for a python library for json_schema generation from python dictoinary

for eg this dictionary

fields = {
  "field1": {"title": "Field1 Title", "type": "string"},
  "field2": {"title": "Field2 Title", "type": "integer"},
  "field3": {"title": "Field3 Title", "type": "numeric", "description": "description", "multipleOf": 0.01},
}

should be processed to next json_schema:

{
    "title": "",
    "type": "object",
    "properties": {
        "field1": {
            "title": "Field1 Title",
            "type": "string"
        },
        "field2": {
            "title": "Field2 Title",
            "type": "integer"
        },
        "field3": {
            "title": "Field3 Title",   
            "description": "description",
            "type": "numeric",
            "multipleOf": 0.01,
        }
    },
    "required": ["field1", "field2"]
}

以 json 形式加载内容 -> json.loads(file)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM