0
votes

I need to load a json file. As it can be seen, '' is replaced by '\' but I've got an error again. How can I fix the bug? The code series is as follows:

    def fetch_bc_data(self):
        bc_file = str(self.decrypt_blockchain_file(str(self.data['id'])))
        bc_file = bc_file.replace("\'", "\"")
        bc = json.loads(bc_file)

    def decrypt_blockchain_file(self, file_name):
        symmetric_key = self.create_symmetric_key(self.user)
        fernet = Fernet(symmetric_key)
        with open('Air/contracts_bc/contract_' + file_name + '_' + self.id + '.bin', 'rb') as file:
            encrypted = file.read()
        file.close()
        decrypted = fernet.decrypt(encrypted)
        return decrypted.decode('UTF-8')

The error I've got is as follows:

json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 235 (char 234)
Are you sure what you got is json? The fact that you had to replace stuff tells me it's not. - Sören
Your data is not valid JSON. You have to fix the data, preferably at the source. - Klaus D.