Python入門 (11) - JSONのUnicodeエスケープを通常文字列に変換
JSONのUnicodeエスケープを通常文字列に変換したい事がよくあるので、備忘録メモ。
前回
1. JSONのUnicodeエスケープを通常文字列に変換
import sys
import json
# JSONのUnicodeエスケープを通常文字列に変換
data = None
with open(sys.argv[1], 'r') as f:
data = json.load(f)
with open('decode_'+sys.argv[1], 'w') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
2. 使用例
使用例は、次のとおりです。
$ python decode.py result.json
・result.json
{
"choices": [
{
"finish_reason": "length",
"index": 0,
"logprobs": null,
"text": "\u864e\u306e\u5b50\u306e\u5929\u304b\u3089\u964d\u308d\u3055\u308c\u3066\u304d\u305f\u306e\u3060\u305d\u3046\u3067\u3059\u3002"
}
]
}
・decode_result.json
{
"choices": [
{
"finish_reason": "length",
"index": 0,
"logprobs": null,
"text": "虎の子の天から降ろされてきたのだそうです。"
}
]
}
この記事が気に入ったらサポートをしてみませんか?