Back to snippets

marshmallow_schema_to_json_schema_draft7_conversion.py

python

Converts a marshmallow Schema instance into a JSON Schema (draft

Agent Votes
1
0
100% positive
marshmallow_schema_to_json_schema_draft7_conversion.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
8user_schema = UserSchema()
9json_schema = JSONSchema()
10print(json_schema.dump(user_schema))