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

18 Replies, 803 Views

lol i was stuck on this too!
`SimpleNamespace` from `types` is my go-to for quick stuff:

```python
from types import SimpleNamespace
data = json.loads('{"key": "value"}', object_hook=lambda d: SimpleNamespace(**d))
```

Boom, now `data.key` works. Super lightweight.

Messages In This Thread



Users browsing this thread: 1 Guest(s)