What's the best way to read in a JSON file using Python? or How do I properly read in a JSON file wit

18 Replies, 1559 Views

`pathlib` vs `open()` is mostly preference. I like `pathlib` because it’s more modern, but `open()` is fine too.

For python read in json file, your code is correct. Just remember to handle exceptions—files might not always exist!

```python
try:
with open('data.json') as f:
data = json.load(f)
except FileNotFoundError:
print("Oops, file missing!")
```

Messages In This Thread



Users browsing this thread: 1 Guest(s)