F
F
fopp1ss2022-03-01 23:34:20
Python
fopp1ss, 2022-03-01 23:34:20

Why does it give an error when reading JSON?

with open(f'example.json', mode='r', encoding='utf-8') as srcfl:
    data = json.load(srcfl)
    print(data)


Error when executing code:
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

JSON itself:
{'autoData': {'carplate': 'b584bk82',
'city_sale': 'The car was sold in the city: Yevpatoriya',
'color': 'BLACK',
'drom.ru': ' https://yevpatoriya.drom .ru/audi/q5/27413672.html ',
'frame': None,
'frame_id': 2955504,
'image': ' https://s.auto.drom.ru/photo/IeOxpiBFzKg-Ds87cwbsi... ' ,
'info': 'Audi Q5 for sale, 2008 in Yevpator',
'model': 'AUDI Q5 ',
'power': 211,
'price': '899\xa0000\xa0₽',
'status': 'For sale on Drom.ru, listing 27413672 from '
'11/25/2017, viewed 427',
'type': 'Station wagon',
'vin': 'WAUZZZ8RX9A004985',
'volume': 1984,
'year': 2008},
'autoDescription': ['Car of the most complete set , there is everything (double
panorama, electric trunk, blind spot camera, etc.) !!! '
'+Studded winter tires on original rims!'],
'autoOsago': {'data': None,
'parse': {'body': 'WAUZZZ8RX9A004985',
'cacheTime': '1645991970',
'id': '12884586',
'insuranceCompany': 'JSC "SK GAYDE"',
'insured': 'Ts***** Alexander Valerievich 27.12.1978',
'kbm': '0.90',
'licensePlate': 'В584ВК82',
'markModel': 'Audi Q5 (category 'B')',
'owner': 'Ц***** Alexander Valerievich 27.12.1978',
'periodicUse': 'Vehicle use period is not active on '
' requested date',
'policyCost':'7860.76 RUB',
'policyIsRestrict': 'Restricted list of persons allowed '
'to control (allowed: 2 people)',
'policyNumber': '0104094940',
'policySeries': 'XXX',
'policyState': 'Ceased',
'regionOfUse': 'Crimea Rep',
'targetUse': 'Personal',
'useWithTrailer': 'No',
'vin': 'WAUZZZ8RX9A004985'},
'statusCode': 200},
'autoPhoto': [' https://s.nomerogram.ru/photo/s3OiCb2pCkj5oafX2x-e. .. ',
' https://s.nomerogram.ru/photo/Px8baPZOwS2XYDz2czUG... ',
'https://s.nomerogram.ru/photo/irK-SJy6LdqfRqf0CJen... ',
' https://s.nomerogram.ru/photo/PZCxW5m9x8_FJFxpkLo2... ',
' https://s.nomerogram.ru/ photo/ZdD19ExMpo2NfW57_GvM... ',
' https://s.nomerogram.ru/photo/FmYAicSzuHlubmpFUR1Z... ',
' https://s.nomerogram.ru/photo/zM7SPgF9q29rIwsEwkWO... ',
' https:/ /s.nomerogram.ru/photo/yWSoNVt6nSeDZehsTn5f... ',
' https://s.nomerogram.ru/photo/Eo16gsbDNLL8o7nP_qny... ',
' https://s.nomerogram.ru/photo/kacv9wn9Wvdqe6ffB_US... ',
' https://s.nomerogram.ru/photo/WChojK4pgnHu7AsSIahT... ',
' https://s.nomerogram.ru/photo/1k0xa6AZnUCAZOckgv98... ',
' https://s.nomerogram.ru/photo /djPYbZauuirt5C2U9qsI... ',
' https://s.nomerogram.ru/photo/f0ERaoU1fXxmtFEfJfRg... '],
'autoRegistration': ['Registration periods as of 21.01.2022',
'13.09.2017-present , individual',
'06.05.2017-13.09.2017, individual',
'28.01.2015-06.05.2017, individual',
'23.10.2013-28.01.2015, individual',
'10/14/2010-10/23/2013, individual', '11/
29/2008-09/30/2010, individual'],
'autoSTS': 'Vehicle certificate (STS) data not found',
'police': {'aiusdtp': 'On the servers of the traffic police, maintenance is carried out. work or server '
'temporarily unavailable',
'diagnostic': 'Tech. inspections in the traffic police database are missing',
'history': {'RequestResult': {'ownershipPeriods': {'ownershipPeriod': [{'from': '2008-11-29',
'lastOperation': '62',
'to': '2010-09-30'},
{'from': '2010-10-14',
'lastOperation': '12',
'simplePersonType': 'Natural',
'to': '2013-10' -23'},
{'from': '2013-10-23',
'lastOperation': '03',
'simplePersonType': 'Natural',
'to': '2015-01-28'},
{'from': '2015-01-28',
'lastOperation': '03',
'simplePersonType': 'Natural',
'to': '2017-05-06'},
{'from': '2017-05-06',
'lastOperation': '03',
'simplePersonType': 'Natural',
'to': '2017-09-13'},
{'from': '2017-09-13',
'lastOperation': '03',
'simplePersonType': 'Natural'}]},
'vehicle': {'bodyNumber': 'WAUZZZ8RX9A004985',
'category': 'B',
'color': 'BLACK',
'engineNumber': 'CDN009783',
'engineVolume': '1984.0',
'model': 'AUDI Q5',
'powerHp': '211.0',
' powerKwt': '155.000',
'type': '21',
'vin': 'WAUZZZ8RX9A004985',
'year': '2008'},
'vehiclePassport': {}},
'hostname': 'h6-check0-dc',
'message': 'ver.3.3',
'registerToken': '18a1ef1bc1781cb15c17d1131d410117c16e16d11911a118',
'regnum' : '',
'requestTime': '03/01/2022 23:01',
'status': 200,
'vin': 'WAUZZZ8RX9A004985'},
'restricted': 'Data on the presence of restrictions in the traffic police database '
'absent',
'wanted': 'Wanted data in the traffic police database is missing'},
'policeCarLocation': 'Crimea, Auto. passed through the yellow light. Penalty for violation of '
'CAO RF is missing',
'url': ['drom.ru: https://yevpatoriya.drom.ru/audi/q5/27413672.html ']}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nochkin, 2022-03-02
@fopp1ss

As already mentioned above, it is better to correct the source.
But if this is not possible, then ast.literal_eval can be used alternatively :

import ast

with open(f'example.json', mode='r', encoding='utf-8') as srcfl:
    data_s = srcfl.read()

data = ast.literal_eval(data_s)
print(data)

S
soremix, 2022-03-01
@SoreMix

Well, actually, in the error it is written that the name of the object in double quotes is expected. You have singles. Single quotes are not valid

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question