I am having below pydantic models.
class SubModel(BaseModel):
columns: Mapping
key: List[str]
required: Optional[List[str]]
class Config:
anystr_strip_whitespace: True
extra: Extra.allow
allow_population_by_field_name: True
class MyModel(BaseModel):
name: str
config1: Optional[SubModel]
config2: Optional[Mapping]
class Config:
anystr_strip_whitespace: True
extra: Extra.allow
allow_population_by_field_name: True
When I am trying to do a dumps
on this, I am getting model is not JSON serializable
from io import BytesIO
from orjson import dumps
bucket = s3.Bucket(bucket_name)
bucket.upload(BytesIO(dumps(data)), key, ExtraArgs={'ContentType': 'application/json'})
Error -
TypeError: Type is not JSON serializable: MyModel
data
is a normal python dictionary with one of item of type MyModel
. Tried to use .json()
but get dict has no attribute json
.
I am stuck here. Can someone help me.