0

I have a problem with reading my files. I got multiple JSON objects and I want to have them in one common JSON file. That is why I want to replace always these \n]\n[ by a comma. My code for doing this looks the following:

with open('name.txt', encoding="utf-8") as fp:
    data = fp.read()
    data = data.replace('\n]\n[', ',')
    data = json.loads(data)
    print(data)

However, I always get this error message although I've included the encoding in the first line:

'charmap' codec can't encode character '\U0001f60b' in position 756: character maps to 
<undefined>

Can anyone please help?

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
  • Does this answer your question? [UnicodeEncodeError: 'charmap' codec can't encode characters](https://stackoverflow.com/questions/27092833/unicodeencodeerror-charmap-codec-cant-encode-characters) – Ulrich Eckhardt Jan 09 '22 at 12:42
  • 1
    Please, next time, first search yourself for the error message. Also, for a proper question here, provide a [mcve] and the full (!) error output it produces. – Ulrich Eckhardt Jan 09 '22 at 12:43
  • If your are on Windows and the error happens in the print statement then you need to configure your terminal for unicode - see [this](https://stackoverflow.com/questions/5419/python-unicode-and-the-windows-console) and [this](https://stackoverflow.com/questions/388490/how-to-use-unicode-characters-in-windows-command-line) – snakecharmerb Jan 09 '22 at 13:08

0 Answers0