How do you properly python cast json as object? Best practices? or What's the correct way to python c

18 Replies, 1172 Views

If you're into libraries, try `pydantic`.
It’s not just for validation—it’s perfect for python cast json as object with dot notation.

```python
from pydantic import BaseModel

class User(BaseModel):
id: int
name: str

user = User.parse_raw('{"id": 1, "name": "Bob"}')
print(user.name) # "Bob"
```

Plus, you get type hints. Win-win!

Messages In This Thread



Users browsing this thread: 1 Guest(s)