I have a file with such non-valid json data (it's cut for clarity):
[
{
"orderID": 90,
"orderDate": '2017-05-10', #issue №1
"clientName": "Mr. Bean",
"clientPhoneN": "123-4567",
"orderContents": [
{
"productID": 05, #issue №2
"productName": "Bicycle",
"quantity": 1,
"price": 8000
},
{
"productID": 23,
"productName": "helmet",
"quantity": 2,
"price": 1000
}
],
"orderCompleted": true
}
]
I tried to open it in python and transform it to list of dictionaries, but with no success. Depending on the case I get different errors. It will take too much space to outline all my attempts and their ending errors.
I have two issues here with the file:
issue №1 - single quotes in orderDate value.
it results with :
JSONDecodeError: Expecting value
issue №2 - zero leading productID.
It results with:
JSONDecodeError: Expecting ',' delimiter
I can hardcode these issues, but I feel that it's not true pythonic way.
Is there an option of "pretty" opening and converting this data file to list of dictionaries?
Most probably I want to keep productID data typa as integer, but if it's impossible, str is ok too.
json. The very question is how to process suchjsonwhich is broken.json, it is close to being JSON format, but needs to be modified before it is JSON, as it is currently simply "data". If you cannot modify the contents of the "data", you will need to use a custom parser.