python serialization json marshmallow

Solutions on MaxInterview for python serialization json marshmallow by the best coders in the world

showing results for - "python serialization json marshmallow"
Nele
15 Jan 2020
1from datetime import date
2from marshmallow import Schema, fields, pprint
3
4class ArtistSchema(Schema):
5    name = fields.Str()
6
7class AlbumSchema(Schema):
8    title = fields.Str()
9    release_date = fields.Date()
10    artist = fields.Nested(ArtistSchema())
11
12bowie = dict(name='David Bowie')
13album = dict(artist=bowie, title='Hunky Dory', release_date=date(1971, 12, 17))
14
15schema = AlbumSchema()
16result = schema.dump(album)
17pprint(result, indent=2)
18# { 'artist': {'name': 'David Bowie'},
19#   'release_date': '1971-12-17',
20#   'title': 'Hunky Dory'}