Skip to content

Instantly share code, notes, and snippets.

@thanakijwanavit
Created April 13, 2021 03:07
Show Gist options
  • Save thanakijwanavit/1512c46e6ebdea2851963e3ebfcef4b8 to your computer and use it in GitHub Desktop.
Save thanakijwanavit/1512c46e6ebdea2851963e3ebfcef4b8 to your computer and use it in GitHub Desktop.
example of using marshmallow with json schema
from marshmallow import Schema, fields
from marshmallow_jsonschema import JSONSchema
class UserSchema(Schema):
name = fields.String()
address = fields.String()
class Athlete(object):
user_schema = UserSchema()
def __init__(self):
self.name = 'sam'
class AthleteSchema(Schema):
user_schema = fields.Nested(JSONSchema)
name = fields.String()
athlete = Athlete()
athlete_schema = AthleteSchema()
athlete_schema.dump(athlete)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment