7

I'm reading a json file in python which has huge amount of imported goods data with their names and taxes. I want to input an item name and search through that file to get tax of that item.

import json

with open("./Files/CD_Data.json") as file:
    #item = input("Enter item name: ")
    reader = json.load(file)
    print(reader)

But when display all data then this error comes up.

UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1626249: `character maps to <undefined>`
3

1 Answer 1

14

It is reasonable to give encoding parameter every time you open a file. Use this:

import json

with open("./Files/CD_Data.json", encoding="utf8") as file:
    #item = input("Enter item name: ")
    reader = json.load(file)
    print(reader)
Sign up to request clarification or add additional context in comments.

1 Comment

Getting JSONDecodeError: Extra data using this exact method. File loading in as TextIOWrapper

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.