Python Forum
json.dumps save some unicode chars as code, not char
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
json.dumps save some unicode chars as code, not char
#1
I use
with open('docs_new.json', 'w') as f:
    f.write(json.dumps(my_json, indent=2))
to write a json object to a file. Some chars are printed as unicode, not chars, e.g. \u201cCreate a new App\u201d instead of “Create a new App”
Part of it was in the original json file and was correct, part of text comes from scraping a website. In both cases in the result file it writes the code.
when I print my_json object, it looks ok.
I'm stuck, what is wrong?
Using python3.5, Linux Mint
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#2
OK, found it
with open('docs_new.json', 'w') as f:
    f.write(json.dumps(my_json, indent=2, ensure_ascii=False))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to save to multiple locations during save cubangt 1 509 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  Can't stop keyboard listener to grab chars typed inside CTk window Valjean 9 1,252 Sep-25-2023, 08:07 PM
Last Post: deanhystad
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 1,054 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  cut string after tow known chars? korenron 3 1,485 Oct-28-2021, 01:23 PM
Last Post: korenron
  How to save json data in a dataframe shantanu97 1 2,121 Apr-15-2021, 02:44 PM
Last Post: klllmmm
  Request for Python code - Features extraction from JSON file (cuckoo) thinker 1 2,147 Apr-07-2021, 04:40 PM
Last Post: Larz60+
  Code failed JSON KeyError popps 3 2,363 Jan-15-2021, 03:45 PM
Last Post: buran
  How to replace on char with another in a string? korenron 3 2,293 Dec-03-2020, 07:37 AM
Last Post: korenron
  How to remove char from string?? ridgerunnersjw 2 2,482 Sep-30-2020, 03:49 PM
Last Post: ridgerunnersjw
  json.dumps list output qurr 12 5,069 Apr-08-2020, 10:13 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020