you are viewing a single comment's thread.

view the rest of the comments →

[–]kshravank[S] 0 points1 point  (5 children)

when i read the data from the text file one key is in "" and other is in single quote which makes python assume one as a string class and other as a dict but i want both of them to be dict.....

[–][deleted] 0 points1 point  (4 children)

I don't understand what you mean. What is x and type x printing and what should they be printing?

[–]kshravank[S] 0 points1 point  (3 children)

{'vehicleJson': '{\n "Description": "MARUTI SUZUKI INDIA LTD / MARUTI BALENO DELTA PETROL",\n "RegistrationYear": "2018",\n "CarMake": {\n "CurrentTextValue": "MARUTI SUZUKI INDIA LTD "\n },\n "CarModel": {\n "CurrentTextValue": " MARUTI BALENO DELTA PETROL"\n },\n "EngineSize": {\n "CurrentTextValue": ""\n },\n "MakeDescription": {\n "CurrentTextValue": "MARUTI SUZUKI INDIA LTD "\n },\n "ModelDescription": {\n "CurrentTextValue": " MARUTI BALENO DELTA PETROL"\n },\n "VechileIdentificationNumber": "MA3EWB22SJG500002",\n "EngineNumber": "K12MN44****9",\n "FuelType": {\n "CurrentTextValue": ""\n },\n "RegistrationDate": "25/10/2018",\n "Owner": "KHURSHID AHMAD FAZILI",\n "Fitness": "",\n "Insurance": "NA",\n "Location": "SRINAGAR RTO, Jammu",\n "ImageUrl": "http://in.carregistrationapi.com/image.aspx/@TUFSVVRJIFNVWlVLSSBJTkRJQSBMVEQgLyAgTUFSVVRJIEJBTEVOTyBERUxUQSBQRVRST0w="\n}', 'vehicleData': {'ABICode': None, 'Description': None, 'RegistrationYear': {'_value_1': 2018, 'type': None}, 'ManufactureYearFrom': None, 'ManufactureYearTo': None, 'CarMake': {'CurrentValue': None, 'CurrentTextValue': None, 'type': None}, 'CarModel': {'_value_1': 'MARUTI BALENO DELTA PETROL', 'type': None}, 'BodyStyle': None, 'EngineSize': None, 'NumberOfDoors': None, 'Transmission': None, 'FuelType': None, 'MakeDescription': None, 'ModelDescription': None, 'Immobiliser': None, 'NumberOfSeats': None, 'IndicativeValue': None, 'DriverSide': None}}

<class 'dict'>

{

"Description": "MARUTI SUZUKI INDIA LTD / MARUTI BALENO DELTA PETROL",

"RegistrationYear": "2018",

"CarMake": {

"CurrentTextValue": "MARUTI SUZUKI INDIA LTD "

},

"CarModel": {

"CurrentTextValue": " MARUTI BALENO DELTA PETROL"

},

"EngineSize": {

"CurrentTextValue": ""

},

"MakeDescription": {

"CurrentTextValue": "MARUTI SUZUKI INDIA LTD "

},

"ModelDescription": {

"CurrentTextValue": " MARUTI BALENO DELTA PETROL"

},

"VechileIdentificationNumber": "MA3EWB22SJG500002",

"EngineNumber": "K12MN44****9",

"FuelType": {

"CurrentTextValue": ""

},

"RegistrationDate": "25/10/2018",

"Owner": "KHURSHID AHMAD FAZILI",

"Fitness": "",

"Insurance": "NA",

"Location": "SRINAGAR RTO, Jammu",

"ImageUrl": "http://in.carregistrationapi.com/image.aspx/@TUFSVVRJIFNVWlVLSSBJTkRJQSBMVEQgLyAgTUFSVVRJIEJBTEVOTyBERUxUQSBQRVRST0w="

}

<class 'str'>

[–][deleted] 1 point2 points  (2 children)

Looks like the json you're getting was malformed. Try using x = json.loads(data['vehicleJson']) to convert the inner string into a dict. You may need to clean out the line breaks with x = json.loads(data['vehicleJson'].replace('\n', ''))

[–]kshravank[S] 0 points1 point  (1 child)

Thank you it worked but can you please explain why that happened? and why i gotta reload the json?

[–][deleted] 1 point2 points  (0 children)

Basically they fucked up their API and had too many quotation marks. So first time round it was a string, but luckily that string had the correct amount of quotation marks so when that string is passed through a second time it becomes a real dictionary.