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, 1555 Views

"Python read in json file – what’s the simplest method?"

Hey folks! So I’ve been messing around with python read in json file stuff, and honestly, it’s kinda confusing at first. Like, there’s a bunch of ways to do it, but which one’s the *easiest*?

I’ve seen people use `json.load()` with files, and `json.loads()` for strings, but tbh, `json.load()` is the way to go if you’re just reading from a file, right?

```python
import json
with open('data.json', 'r') as f:
data = json.load(f)
```

Boom, done. Or am I missing something?

Also, why do some folks use `pathlib` instead of `open()`? Overkill or actually better?

Would love to hear how y’all handle python read in json file tasks!

Messages In This Thread
What's the best way to read in a JSON file using Python? or How do I properly read in a JSON file wit - by - 19-04-2024, 08:02 PM



Users browsing this thread: 1 Guest(s)