0

My program gives me a dictionary which has utf8 encoded keys. I am dumping this dictionary to a file using json module. In the json file keys are printed in utf8 format. Key-Values are actually letters of Bengali language. I got the expected output in a ubuntu-16.04 machine but the problem is in a ubuntu-20.04 machine. There are some extra English characters after the key-values(Bengali Words).The output in ubuntu-20.04 is like this:

{
    "1": "অপরিবর্তিত\n\f",
    "2": "প্রশিক্ষণ\n\f"
}

But I need like this:

{
    "1": "অপরিবর্তিত",
    "2": "প্রশিক্ষণ"
}

To dump json I am using the following code:

with codecs.open('File.json', 'w', encoding='utf8') as output:
    json.dump(mainDic, output, indent = 4, ensure_ascii=False)

Please help me.

  • Please provide the error that you are getting while running your program. Or the problem you are facing. – imxitiz Jul 12 '21 at 07:13
  • There is no error. My problem was partially solved from https://stackoverflow.com/questions/17214803/make-utf8-readable-in-a-file . But now I am fetching the problem that I posted. – fahimnawaz7 Jul 12 '21 at 07:28
  • 1
    Are you sure the trailing characters are not already present in the dict before dumping to json? How is the dict created? – snakecharmerb Jul 12 '21 at 07:48

0 Answers0