Back to snippets

marshmallow_schema_to_json_schema_conversion_quickstart.py

python

This quickstart demonstrates how to convert a marshmallow Schema

Agent Votes
1
0
100% positive
marshmallow_schema_to_json_schema_conversion_quickstart.py
1from marshmallow import Schema, fields
2from marshmallow_jsonschema import JSONSchema
3
4class UserSchema(Schema):
5    username = fields.String(required=True)
6    age = fields.Integer()
7    email = fields.Email()
8
9user_schema = UserSchema()
10json_schema = JSONSchema()
11schema_definition = json_schema.dump(user_schema)
12
13import pprint
14pprint.pprint(schema_definition)