0

so i am trying to load a JSON file that happens to be 28 mb (IDK if thats important to know) my code is

json_file = ("city_list.json")
with open("json_file", "r") as file:
   data = json.load(file)
 print(data)

my JSOn file is formated like this (With a lot more elements:

{
 "id": 2522914,
 "name": "Torre di Faro",
 "country": "IT",
 "coord": {
 "lon": 15.65,
 "lat": 38.26667
 }
},
{
 "id": 7156618,
 "name": "Bryce Canyon City",
 "country": "US",
 "coord": {
 "lon": -112.156937,
 "lat": 37.673889
 }

and the error i am getting is:

File "D:/Project/Weather.py", line 20, in <module>
    data = json.load(file)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 321: character maps to <undefined>

what am i doing wrong here?

1 Answers1

0

Most likely your JSON file is in the wrong encoding. So you have a character code that the JSON parser does not know how to interpret. See this answer for more information.

see sharper
  • 11,505
  • 8
  • 46
  • 65