Reputation: 5004
I've more then 1GB json file with encoded strings inside. For example:
{
"id": "3",
"billing_type": {
"id": "standard",
"name": "\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442"
},
"area": {
"id": "1",
"name": "\u041c\u043e\u0441\u043a\u0432\u0430"
}
}
How I can decode like this \u041c\u043e
string inside my json file in my case?
Upvotes: 0
Views: 582
Reputation: 512
if you use python3, just import json
will help.
import json
result = json.loads(json_data)
print(result)
or python2, you should use encode
method for each values (after check type first)
result = json.loads(json_data)
for k, v in result.items():
if isinstance(v, dict):
for dk, dv in v.items():
print dk.encode("utf-8"), dv.encode("utf-8")
else:
print k.encode("utf-8"), v.encode("utf-8")
Upvotes: 2
Reputation: 483
data = "\u041c\u043e\u0441\u043a\u0432\u0430"
data = data.encode().decode('unicode-escape')
This might be a solution.
Upvotes: 1