Answer the question
In order to leave comments, you need to log in
How to translate JSON to PythonObj without bugs?
There is a function:
def load_data(filepath):
data = []
with open(filepath) as f:
for line in f:
data.append(json.loads(line)) #convert JSON to Python object
print(data)
return data
{u'type': u'Point', u'coordinates': [37.717115000077776, 55.78262800012168]}, u'SocialPrivileges': u'\u043d\u0435\u0442', u'AdmArea': u'\u0412\u043e\u0441\u0442\u043e\u0447\u043d\u044b\u0439 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043e\u043a\u0440\u0443\u0433', u'SeatsCount': 177}, u'Id': u'4644e029-30f7-4e9c-8a1e-1ec20595f564', u'Number': 515}]]
ensure_ascii=False, sort_keys=True, indent=4
?
Answer the question
In order to leave comments, you need to log in
import json
with open(file_path) as file:
data = json.load(file)
from pprint import pprint
data = {'key1': 'value1', 'key2': {'key2.1': 'value2.1', 'key2.2': {'key2.2.1': 'value2.2.1', 'key2.2.2': 'value2.2.2'}, 'key2.3': 'value2.3'}, 'key3': 'value3'}
>>> pprint(data)
{'key1': 'value1',
'key2': {'key2.1': 'value2.1',
'key2.2': {'key2.2.1': 'value2.2.1', 'key2.2.2': 'value2.2.2'},
'key2.3': 'value2.3'},
'key3': 'value3'}
It will transform normally for you. You can display it on the screen without using json.dumps like this .
Dmitry Azarenko brought a great option.
You can also dump d json with the parameters you specify, what you print and print the result of the dump, not repr
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question