I am trying to decode, then parse a JSON file it's about 9MB. But when I try to decode the json file, to make it into a python dictionary object I get the error:
'utf8' codec can't decode bytes in position 3161744-3161747: invalid data
I think this might be because of encoding/decoding issues, but I'm not entirely certain. I don't know what the file is being encoding as because I am getting it from a third party, and unfortunately I can't show the file because it contains sensitive information.
Also, the people who supplied the JSON file said it's a valid JSON file and passes json lint. Here is my code below:
import json
""" JSON Parser """
class parser:
json_file = None
""" The JSON File name"""
def json_object(self, file):
self.json_file = file
""" Open up file and parse it """
def json_encode(self):
try:
json_data = open(self.json_file)
data = json_data.read().decode('utf8')
result = json.loads(data)
except Exception as e:
result = e
return result
""" Instantiate parser and begin parsing the file"""
p = parser()
p.json_object('file.js')
print p.json_encode()
data[3161730:3161760]to see what's causing the error?