1

I am trying to json dump a dictionary that contains unicode characters

bible_text = 
 {'Amos': 
  {'Chapter 02': 
    {'Verse 01': 'כֹּ֚ה אָמַ֣ר יְהֹוָ֔ה עַל־ שְׁלֹשָׁה֙ פִּשְׁעֵ֣י מוֹאָ֔ב וְעַל־ אַרְבָּעָ֖ה לֹ֣א אֲשִׁיבֶ֑נּוּ עַל־ שׇׂרְפ֛וֹ עַצְמ֥וֹת מֶלֶךְ־ אֱד֖וֹם לַשִּֽׂיד׃'}
  }
 }

When I do so as such:

open(TEXT_JSON,'w').write(json.dumps(bible_text, sort_keys=True, indent=2))

The resulting output is in unicode strings (and not the original characters):

{'Amos': 
  {'Chapter 02': 
    {'Verse 01': "\u05db\u05bc\u05b9\u059a\u05d4 \u05d0\u05b8\u05de\u05b7\u05a3\u05e8 \u05d9\u05b0\u05d4\u05b9\u05d5\u05b8\u0594\u05d4 \u05e2\u05b7\u05dc\u05be \u05e9\u05c1\u05b0\u05dc\u05b9\u05e9\u05c1\u05b8\u05d4\u0599 \u05e4\u05bc\u05b4\u05e9\u05c1\u05b0\u05e2\u05b5\u05a3\u05d9 \u05de\u05d5\u05b9\u05d0\u05b8\u0594\u05d1 \u05d5\u05b0\u05e2\u05b7\u05dc\u05be \u05d0\u05b7\u05e8\u05b0\u05d1\u05bc\u05b8\u05e2\u05b8\u0596\u05d4 \u05dc\u05b9\u05a3\u05d0 \u05d0\u05b2\u05e9\u05c1\u05b4\u05d9\u05d1\u05b6\u0591\u05e0\u05bc\u05d5\u05bc \u05e2\u05b7\u05dc\u05be \u05e9\u05c2\u05c7\u05e8\u05b0\u05e4\u059b\u05d5\u05b9 \u05e2\u05b7\u05e6\u05b0\u05de\u05a5\u05d5\u05b9\u05ea \u05de\u05b6\u05dc\u05b6\u05da\u05b0\u05be \u05d0\u05b1\u05d3\u0596\u05d5\u05b9\u05dd \u05dc\u05b7\u05e9\u05c2\u05bc\u05b4\u05bd\u05d9\u05d3\u05c3"}
  }
 }

But I want to preserve the original unicode characters in the output json.

How can I json dump unicode characters?

etayluz
  • 15,920
  • 23
  • 106
  • 151

0 Answers0