I am using Marshmallow for serialization and de-serialization of JSON strings. From the Marshmallow API Docs (https://marshmallow.readthedocs.io/en/3.0/api_reference.html), it looks like you have specify a list of fields (and, unless using Meta
) their data type. For example:
Marital_Status=Fields.Str()
Employer=Fields.Str()
ContactInfo(data) #where ContactInfo is a class not shown here
However, I already have a JSON schema that specifies the fields and the data types. For example:
the_template_schema={
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
"properties": {
"Marital_Status": {
"$id": "#/properties/Marital_Status",
"type": "string",
"title": "The Marital_status Schema",
"default": "",
"examples": [
"Married"
],
"pattern": "^(.*)$"
}
"Employer": {
"$id": "#/properties/Employer",
"type": "string",
"title": "The Employer Schema",
"default": "",
"examples": [
"Roivant"
],
"pattern": "^(.*)$"
}
}
}
My Question
I want to specify to Marshmallow the fields, based on the schema data provided. Something like:
fields.magicmethod(the_template_schema)
ContactInfo(data)
Is this possible? If so, how?