3

I'm loading a json file on my computer. I can load it in without specifying the encoding on Kaggle, no, errors. On my PC I get the error in the title.

with open('D:\soccer\statsbomb360\matches.json') as f:
    data = json.load(f, encoding = 'utf8')

Adding errors = 'ignore' or changing encoding to 'latin' doesn't work either. I'm a bit lost on what to try next, can you give me an idea?

The json is from statsbombs freely available data. Interestingly from the same dataset I have some files that give me this error on Kaggle/Colab but not on my pc, but there specifying encoding = 'latin' did the trick.

thank you!

Olli
  • 906
  • 10
  • 25
  • 2
    Put the encoding parameter in the open – Mark Tolonen Mar 23 '22 at 20:18
  • @MarkTolonen You are a lifesaver, this worked! So many people couldn't figure it out yesterday. Thanks! Do you want to add this as an answer? I gladly accept it as solution! – Olli Mar 24 '22 at 12:40

1 Answers1

6

Try

with open('D:\soccer\statsbomb360\matches.json', encoding="utf8") as f:
    data = json.load(f)

per @mark-tolonen

Also see this post: UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to <undefined>

Herman Autore
  • 136
  • 2
  • 12