How to put JSON data into a dictionary Python – what's the best way? or Struggling with how to put JS

14 Replies, 1283 Views

if you’re struggling with how to put json data into a dictionary python, here’s a pro tip:

use `json.loads()` for strings and `json.load()` for files.

example for a file:
```python
import json

with open('data.json', 'r') as file:
my_dict = json.load(file)
```

this automatically closes the file too, so no leaks. easy peasy!

Messages In This Thread



Users browsing this thread: 1 Guest(s)