0

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

for e.g 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"]
}
supspec
  • 3
  • 2
  • 1
    Python is a dynamic language so it's pretty simple to walk the first data structure to turn it into the second. – Ether Jul 19 '21 at 21:36
  • You would want to do custom key, value mapping for this, as its not 1:1 mapping in your case. Please refer to this thread's answer(s): https://stackoverflow.com/questions/26745519/converting-dictionary-to-json – Raj Verma Jul 20 '21 at 08:31

1 Answers1

-2

To load content in json form -> json.loads(file)