0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Python] JSONファイルに日本語をそのまま出力したい

Posted at

背景と課題

with open('test.json', 'w', encoding='utf-8') as json_file:
    json.dump("あいうえお", json_file)

上記のように日本語のテキストをJSONファイルに出力したのち、JSONファイルを開くと下記のように出力された。

"\u3042\u3044\u3046\u3048\u304a"

このように、\uから始まる形式を「Unicode Escape Sequence」(以降、UESと呼ぶ)というらしい

対応策

  • json.dumpの引数にensure_ascii=Falseを設定する
with open('test.json', 'w', encoding='utf-8') as json_file:
    json.dump("あいうえお", json_file, ensure_ascii=False)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?