[b]"What's the best way to read JSON from a file in Python?"[/b] or [b]"How do I properly read JSON from a file in

18 Replies, 594 Views

Ugh, json read from file python can be such a pain sometimes. One thing that tripped me up was extra whitespace or BOM characters.

Try this:

```python
import json
with open('file.json', 'r') as f:
content = f.read().strip()
data = json.loads(content)
```

Also, print `content` before loading to see if it looks weird.

Messages In This Thread



Users browsing this thread: 1 Guest(s)