Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138192

Sending JSON obj with Japanese characters from Python to Javascript

$
0
0

I have a Python3 function that when called will return a json object which looks like this:

finished python tags look like this:
{'tags': {'releaseArtist': ['Shuichi Murakami', 'Nobu Caine', 'Electro Keyboard Orchestra', 'Mash', 'Loser', 'Ponta Box', 'Mobo Band', 'JOQR DJ Girls', 'Miro Takebi Trio', 'Nobu-Zans', '7 Seven', 'Ponta Unit'], 'releaseInfo': ['Welcome To My Life', '1998', 'Japan', 'JVC', 'Jazz'], 'tracklist': ['Jaco Pastorius Medley = ジャコ・パトリアス・メドレー', 'I Want You Back = アイ・ウォント・ユー・バック', 'Travelling = トラベリング', 'Ive Got You Under My Skin = アイヴ・ガット・ユー・アンダー・マイ・スキン', '青い山脈', 'Oh! Darling = オー!
ダーリン', 'Jane Birkin Medley = ジェーン・バーキン・メドレー', '津軽 ~ 南部俵積み唄', 'It Might As Well Stay Monday From Now On = 月曜はブルーな日', 'Time Is On My Side = タイム・イズ・オン・マイ・サイド', 'We Can Talk = ウィ・キャン・トーク', 'Left Alone = レフト・ア
ローン', 'ヨイトマケの唄', 'Mambo No. 5 = マンボ・ナンバー5', '(The White Room ~ Sunshine Of Your Love) ~ Knockin On Heavens Door = 天国への扉', 'Welcome To My Rhythm [こんなオイラに誰がした] ~ 嵐を呼ぶ男'], 'combinations': ['Welcome To My Life 1998', 'Shuichi Murakam
i 1998', 'Shuichi Murakami Welcome To My Life', 'Shuichi Murakami Welcome To My Life 1998']}}
json data =  {'tags': {'releaseArtist': ['Shuichi Murakami', 'Nobu Caine', 'Electro Keyboard Orchestra', 'Mash', 'Loser', 'Ponta Box', 'Mobo Band', 'JOQR DJ Girls', 'Miro Takebi Trio', 'Nobu-Zans', '7 Seven', 'Ponta Unit'], 'releaseInfo': ['Welcome To My Life', '1998', 'Japan', 'JVC', 'Jazz'], 'tracklist': ['Jaco Pastorius Medley = ジャコ・パトリアス・メドレー', 'I Want You Back = アイ・ウォント・ユー・バック', 'Travelling = トラベリング', 'Ive Got You Under My Skin = アイヴ・ガット・ユー・アンダー・マイ・スキン', '青い山脈', 'Oh! Darli
ng = オー! ダーリン', 'Jane Birkin Medley = ジェーン・バーキン・メドレー', '津軽 ~ 南部俵積み唄', 'It Might As Well Stay Monday From Now On = 月曜はブルーな日', 'Time Is On My Side = タイム・イズ・オン・マイ・サイド', 'We Can Talk = ウィ・キャン・トーク', 'Left Alone =レフト・アローン', 'ヨイトマケの唄', 'Mambo No. 5 = マンボ・ナンバー5', '(The White Room ~ Sunshine Of Your Love) ~ Knockin On Heavens Door = 天国への扉', 'Welcome To My Rhythm [こんなオイラに誰がした] ~ 嵐を呼ぶ男'], 'combinations': ['Welcome To My Life 1998', 'Shui
chi Murakami 1998', 'Shuichi Murakami Welcome To My Life', 'Shuichi Murakami Welcome To My Life 1998']}}

my Python functionr returns the JSON like this:

#format tags
tags = {}
tags["releaseArtist"] = artistsTags 
tags["releaseInfo"] = releaseInfoTags
tags["tracklist"] = tracklistTags
tags["combinations"] = combinationsTags
data = {}
data["tags"] = tags
print('finished python tags look like:')
print(data)
return data

My javascript in an html file receives the tags json data structure like this:

            console.log("ajax request to /my-ajax-test/ was a success !")
            console.log("response = ", response)                                 //encoded output
            console.log("JSON.stringify(response) = ", JSON.stringify(response)) //encoded output
            //console.log("JSON.loads(response) = ", JSON.loads(response))       //no json.loads function
            console.log("JSON.parse(response) = ", JSON.parse(response))         //encoded output

When I print the received json data; all the Japanese characters get encoded like \u9752\u3044\u5c71\u8108:

response =  {"tags": {"releaseArtist": ["Shuichi Murakami", "Nobu Caine", "Electro Keyboard Orchestra", "Mash", "Loser", "Ponta Box", "Mobo Band", "JOQR DJ Girls", "Miro Takebi Trio", "Nobu-Zans", "7 Seven", "Ponta Unit"], "releaseInfo": ["Welcome To My Life", "1998", "Japan", "JVC", "Jazz"], "tracklist": ["Jaco Pastorius Medley = \u30b8\u30e3\u30b3\u30fb\u30d1\u30c8\u30ea\u30a2\u30b9\u30fb\u30e1\u30c9\u30ec\u30fc", "I Want You Back = \u30a2\u30a4\u30fb\u30a6\u30a9\u30f3\u30c8\u30fb\u30e6\u30fc\u30fb\u30d0\u30c3\u30af", "Travelling = \u30c8\u30e9\u30d9\u30ea\u30f3\u30b0", "Ive Got You Under My Skin = \u30a2\u30a4\u30f4\u30fb\u30ac\u30c3\u30c8\u30fb\u30e6\u30fc\u30fb\u30a2\u30f3\u30c0\u30fc\u30fb\u30de\u30a4\u30fb\u30b9\u30ad\u30f3", "\u9752\u3044\u5c71\u8108", "Oh! Darling = \u30aa\u30fc\uff01 \u30c0\u30fc\u30ea\u30f3", "Jane Birkin Medley = \u30b8\u30a7\u30fc\u30f3\u30fb\u30d0\u30fc\u30ad\u30f3\u30fb\u30e1\u30c9\u30ec\u30fc", "\u6d25\u8efd \uff5e \u5357\u90e8\u4ff5\u7a4d\u307f\u5504", "It Might As Well Stay Monday From Now On = \u6708\u66dc\u306f\u30d6\u30eb\u30fc\u306a\u65e5", "Time Is On My Side = \u30bf\u30a4\u30e0\u30fb\u30a4\u30ba\u30fb\u30aa\u30f3\u30fb\u30de\u30a4\u30fb\u30b5\u30a4\u30c9", "We Can Talk = \u30a6\u30a3\u30fb\u30ad\u30e3\u30f3\u30fb\u30c8\u30fc\u30af", "Left Alone = \u30ec\u30d5\u30c8\u30fb\u30a2\u30ed\u30fc\u30f3", "\u30e8\u30a4\u30c8\u30de\u30b1\u306e\u5504", "Mambo No. 5 = \u30de\u30f3\u30dc\u30fb\u30ca\u30f3\u30d0\u30fc5", "(The White Room \uff5e Sunshine Of Your Love) \uff5e Knockin On Heavens Door = \u5929\u56fd\u3078\u306e\u6249", "Welcome To My Rhythm [\u3053\u3093\u306a\u30aa\u30a4\u30e9\u306b\u8ab0\u304c\u3057\u305f] \uff5e \u5d50\u3092\u547c\u3076\u7537"], "combinations": ["Welcome To My Life 1998", "Shuichi Murakami 1998", "Shuichi Murakami Welcome To My Life", "Shuichi Murakami Welcome To My Life 1998"]}}

So the json data is fine when its in Python, but once it reaches javascript it encodes complex chars, and my attempts to decode it with json.parse / json.loads / json.stringify havent been successfull. Is there a way to ensure that my Javascript always has the same chars as in Python? (For languages with chars like Japan, Middle Eastern, etc...)


Viewing all articles
Browse latest Browse all 138192

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>