How to handle embedded objects in Python json.dumps? Struggling with serialization! or Best way to se

14 Replies, 1060 Views

If you’re dealing with python json.dumps embedded object problems, `pydantic` might be overkill but it’s *so* nice for serialization.

Define your model with proper types, and it handles json conversion automatically.

Example:

```python
from pydantic import BaseModel

class YourModel(BaseModel):
...

json_str = YourModel.parse_obj(your_object).json()
```

No more encoder headaches!

Messages In This Thread



Users browsing this thread: 1 Guest(s)