I'm trying to write a script that takes a json file pizza-train.json and extracts the request_text field from each dictionary in the list. But im getting an error when running the below code:
Code:
import json
json1_file = open("pizza-train.json", 'r')
json1_str = json1_file.read()
json1_data = json.loads(json1_str)
print(json1_data)
Error:
File "C:\Python34\lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 58765-58767: character maps to
I've tried different solutions, such as: encoding="UTF-8"
.encode('utf-8')
Can anyone explain my why it wont print the json1_data ?
print(json1_data)
line? If yes, then you can't print non-Windows1252 chars in your console since this is your console charset. – user996142chcp
. Long answer is below – user996142