Skip to content Skip to sidebar Skip to footer

Converting A Dictionary To Json Using Json.dumps Having Arabic Characters

I have a dictionary containing arabic words like data = [{'name': 'آدَم'}, {'name': 'آزَر'}] print(json.dumps(data), file=open('data.json', 'a', encoding='utf-8')) Output:

Solution 1:

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.

Post a Comment for "Converting A Dictionary To Json Using Json.dumps Having Arabic Characters"