Best way to convert json to dict in function python? Need help! or How to properly handle json to dic

22 Replies, 1784 Views

For json to dict in function python, you could add a default param.

```python
def json_to_dict(json_str, default=None):
try:
return json.loads(json_str)
except:
return default
```

This way, you control what happens on failure.

Messages In This Thread



Users browsing this thread: 1 Guest(s)