marshmallow-oneofschema
marshmallow-oneofschema copied to clipboard
Help to deserialize complex JSON
I need to deserialize this JSON:
{
"emails": {
"items": [
{
"id": 1,
"email": "[email protected]"
},
{
"id": 2,
"email": "[email protected]"
}
]
}
}
Into this object using Marshmallow:
{
"emails": [
{
"id": 1,
"email": "[email protected]"
},
{
"id": 2,
"email": "[email protected]"
}
]
}
How can I do it?
I tried this way, which I found more intuitive, but it did not work:
class Phone(OrderedSchema):
id = fields.Int()
email = fields.Str()
class Contact(Schema):
key = fields.Str()
phones = fields.Nested(Phone, load_from='phones.list', many=True)
@vcamaral please close this as duplicate of https://github.com/marshmallow-code/marshmallow/issues/873.