I
I
IlyuhaShprotov2020-08-31 14:19:29
Python
IlyuhaShprotov, 2020-08-31 14:19:29

It is written to a json file in a different encoding, although I set ensure_ascii=False. What to do?

I want to make it so that a dictionary with data about a person is recorded. Here is the code:

import json

start = {
    "money":"100",
    "reputation":"0",
    "rank":"Нет",
    "devices":"Нет",
    "Донат":"Нет"
}

dict.update([(id, start)])

with open('main.json', 'w', encoding="utf-8") as file:
            json.dump(dict, file, ensure_ascii=False, indent=4)


Everything works correctly, but for some reason it is written like this:

{
    "484175786": {
        "money": "100",
        "reputation": "0",
        "rank": "None",
        "devices": "Нет",
        "Донат": "Нет"
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2020-08-31
@bacon

If you open utf-8 as windows-1251, then that's exactly what it will be.

R
Roman Mirilaczvili, 2020-09-01
@2ord

Everything is already written in UTF-8 without any ensure_ascii=False. Non-ASCII characters can be encoded as \uXXXX when written to JSON

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question