Paste SQLAlchemy model classes and get example JSON keyed by the column attribute names. It reads 2.0-style Mapped[...] with mapped_column(), 1.x-style Column(), and Flask-SQLAlchemy's db.Column(), and merges in columns from mixins and parent classes.
SQLAlchemy models cannot be passed to json.dumps directly, so FastAPI and Flask apps add Pydantic or Marshmallow schemas. Use this to lay out which fields a model will expose before writing that schema, or to build request bodies for tests.
SQLAlchemy box. Keep Base, mixins and enum.Enum classes in the same input so inherited columns and enum values resolve.__tablename__ count as models. Several models are output by class name, like { "User": {...}, "Team": {...} }.class TimestampMixin:
created_at = db.Column(db.DateTime, default=datetime.utcnow)
class Plan(enum.Enum):
FREE = "free"
PRO = "pro"
class Subscription(TimestampMixin, db.Model):
__tablename__ = "subscriptions"
id = db.Column(db.Integer, primary_key=True)
plan = db.Column(db.Enum(Plan), nullable=False)
seats = db.Column(db.SmallInteger, default=1)
trial_ends = db.Column(db.Date)
user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
user = db.relationship("User", backref="subscriptions"){
"created_at": "1970-01-01T00:00:00",
"id": 0,
"plan": "free",
"seats": 1,
"trial_ends": "1970-01-01",
"user_id": 0
}created_at from TimestampMixin comes first, following inheritance order, and user is dropped because relationship() is not a column. db.Enum(Plan) takes the enum's first value, "free", and db.Date becomes 1970-01-01. seats shows 1 from default=1, while created_at keeps the placeholder because datetime.utcnow is a function.
Mapped[int], Mapped[Optional[str]] and Mapped[str | None] decide the value.Column(String(50)) or db.Column(db.Numeric).DateTime → 1970-01-01T00:00:00, Date → 1970-01-01, Time → 00:00:00, JSON/JSONB → {}, Uuid → an all-zero UUID.ARRAY(String) and Mapped[list[str]] become one-element arrays.enum.Enum, used via Enum(Plan) or Mapped[Plan], contributes its first member's value.relationship(), column_property(), plain class variables and dunder attributes like __table_args__ are excluded.Before writing the Pydantic class for FastAPI's response_model, check the fields and types the model exposes as JSON. Feed that JSON to the JSON to Python page to get a Pydantic draft as well.
Build the body for client.post("/subscriptions", json=...) with keys that match the model's attributes. Strip the autoincrement id and creation time first.
default= ("new", 1, True, None) is used as the sample value; callables like datetime.utcnow or dict are not run. server_default= and nullable= are not read.Column("user_name", String), the JSON key is still the Python attribute name.relationship are not included. Add nested objects yourself if your response embeds them.hybrid_property or @property are not part of the output.Mapped[Optional[str]] an empty string instead of null?Optional means None is allowed; the example shows the case where a value is present, so it uses the inner str. Change it to null in the output if you need that case.
Z or offset?DateTime columns are naive by default, and isoformat() prints them without an offset. If you use DateTime(timezone=True), an example with +00:00 is closer to what you will actually see.
No. This page understands SQLAlchemy's Column, mapped_column and Mapped syntax only; Django fields like models.CharField are not recognized.