marshmallow-oneofschema icon indicating copy to clipboard operation
marshmallow-oneofschema copied to clipboard

Help to deserialize complex JSON

Open vcamaral opened this issue 5 years ago • 1 comments

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 avatar Jul 05 '18 15:07 vcamaral

@vcamaral please close this as duplicate of https://github.com/marshmallow-code/marshmallow/issues/873.

lafrech avatar Jul 05 '18 19:07 lafrech