How do you load a JSON file in your code? Best methods? or Struggling with JSON files—how do you load

18 Replies, 1153 Views

how do you load a json file without losing your mind? 😅

Python:
```python
import json
try:
with open('data.json') as f:
stuff = json.load(f)
except FileNotFoundError:
print("Oops, file missing!")
except json.JSONDecodeError:
print("JSON is borked!")
```

JS: `fetch` is cool, but for quick and dirty, just paste the JSON into a variable. Not elegant, but works!

Messages In This Thread



Users browsing this thread: 1 Guest(s)