0

I tried:

# -*- coding: utf-8 -*-
with open("File1", "w") as outfile:
    json.dump( {"Tytuł":"tą"}, outfile, indent = True, encoding="utf-8")

Which gives me:

{
"Tytu\u0142": "t\u0105"
}

What'd I like to get is:

{
"Tytuł": "tą"
}

ensure_ascii=False works, but when I try to get JSON data from the file, I get UnicodeEncodeError: 'ascii' codec can't encode characters...

The code I'm using for this is:

json_data=open('File0')
data = json.load(json_data)
with open("File1", "w") as outfile:
    json.dump( data,outfile,indent = True,ensure_ascii=False)
user7172
  • 874
  • 4
  • 16
  • 31

1 Answers1

1

Try setting argument ensure_ascii to False:

with open("File1", "w") as outfile:
    json.dump( {"Tytuł":"tą"}, outfile, indent = True, encoding="utf-8", ensure_ascii=False)
Logan Ding
  • 1,761
  • 1
  • 12
  • 23