簡體   English   中英

如何從python dict生成json模式

[英]How to generate json schema from python dict

我正在尋找一個用於從 python dictoinary 生成 json_schema 的 python 庫

例如這本詞典

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

應該處理到下一個 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM