9

I have a dictionary containing arabic words like

data = [{'name': 'آدَم'}, {'name': 'آزَر'}]
print(json.dumps(data), file=open('data.json', 'a', encoding="utf-8"))

Output:

[{"name": "\u0622\u0632\u064e\u0631"}...]

I don't want to encode the arabic text while creating the data.json file. If I do not use json.dumps then it works fine but then it shows single quotes ' instead of double qoutes "

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
coure2011
  • 40,286
  • 83
  • 216
  • 349

1 Answers1

23

Pass the parameter ensure_ascii = False:

json.dumps(data, ensure_ascii = False)

Documentation here.

If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped. If ensure_ascii is false, these characters will be output as-is.

Phylogenesis
  • 7,775
  • 19
  • 27