1

I use this piece of code to convert a .csv file content to a .json file:

import csv
import json

with open('export.csv', encoding='utf-8') as f:
    reader = csv.DictReader(f)
    rows = list(reader)

with open('test.json', 'w', encoding='utf-8') as f:
    json.dump(rows, f)

The conversion is successful, but Arabic characters in .csv file convert to something like this in .json file:

"\u06a9\u0627"

How can I solve this?

1 Answer 1

2

According to json.dump docstring:

If ensure_ascii is false, then the strings written to fp can contain non-ASCII characters if they appear in strings contained in obj. Otherwise, all such characters are escaped in JSON strings.

Solution:

json.dump(rows, f, ensure_ascii=False)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.