Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how json dump Japanese

I am coding a spider-code to collect message on a Japanese website, storing data using json-module

however, default json dump the data with Unicode. cant see raw Japanese

I see one solution on the internet is
but, this keyword is not available in json dump!
this code raise an error that cant decode the 'gbk'!

but i cant encode my data structure into Unicode.
how can I see raw Japanese in my json file?
import json
my_data = '{"some_japanese_text":"このコーディネートのスタイリストについて"}'

# load it in a dict
json_data = json.loads(my_data, encoding='utf-8')

# print the sting
print(json.dumps(json_data, indent=2, ensure_ascii=False))

# or write it to foo.json
with open('foo.json', 'w') as jf:
    json.dump(json_data, jf, indent=2, ensure_ascii=False)
<class 'dict'> { "some_japanese_text": "このコーディネートのスタイリストについて" }
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

To JSON serialize Unicode or non-ASCII data as-is strings instead of \u escape sequence.

The json.dump() and json.dumps() has a ensure_ascii parameter. The ensure_ascii is by-default true so the output is guaranteed to have all incoming non-ASCII characters escaped. If ensure_ascii=False, these characters will be output as-is.

json.dumps('このコーディネートのスタイリストについて', ensure_ascii=False)

Possibly Related Threads…
Thread Author Replies Views Last Post
  UnicodeEncodeError - Dealing with Japanese Characters fioranosnake 2 616 Jul-07-2022, 08:43 PM
Last Post: fioranosnake
  Python html herf to json dump help paulfearn100 0 1,535 Mar-03-2020, 09:16 PM
Last Post: paulfearn100
  print python json dump onto multiple lines lhailey 2 15,567 Mar-02-2020, 12:47 PM
Last Post: vishalhule
  creating hex dump modifying program ensoniq 3 2,045 Oct-14-2019, 08:21 AM
Last Post: Larz60+
  Type error: dump() missing 1 required positional argument: fp jaycuff13 2 18,703 Jul-13-2019, 10:21 AM
Last Post: jaycuff13
  Using pickle.dump Friend 1 2,412 Feb-15-2019, 04:39 PM
Last Post: metulburr
  tf.gfile.FastGFile error unicode ( japanese characters ) majinbuu 2 2,568 May-13-2018, 02:11 PM
Last Post: majinbuu

Forum Jump:

User Panel Messages

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