How to properly json read json file in Python? or What's the best way to json read json file without

18 Replies, 1461 Views

Encoding hell, right? When you json read json file, always assume the worst.

Try this:

```python
with open('data.json', 'rb') as f:
raw = f.read().decode('utf-8-sig') # kills BOM if present
data = json.loads(raw)
```

BOM chars are sneaky and will wreck your day. This’ll strip ’em out.

Messages In This Thread



Users browsing this thread: 1 Guest(s)