I have a string like this
"{""netPrice"":251.6,""totalPrice"":299.4,""calculatedTaxes"":[{""tax"":47.8,""taxRate"":19.0,""price"":251.6,""extensions"":[]}],""taxRules"":[{""taxRate"":19.0,""percentage"":100.0,""extensions"":[]}],""positionPrice"":232.0,""rawTotal"":299.4,""taxStatus"":""net""}"
and i need it to be an dict like {'netPrice': 251.6, 'totalPrice':299.4, and so on}
but since it hast the double quotes eval and json doesnt work for this.
I import that string out of a csv file with
with open('order.csv', 'r') as csv_datei:
for row in csv_datei:
so i cant get it in a cleaner format as far as i know. (the String is the row)
How do I convert it into a dict?
print(repr(str))
to check exactly what is in it? It looks like it might be a JSON string. If so, usejson.loads
on it.order.csv
file, as it seems like the result of encoding JSON into CSV, usecsv.reader
to read it, thenjson.loads
to parse it.print(repr(str))
i get'"{""netPrice"":251.6,""totalPrice"":299.4,""calculatedTaxes"":[{""tax"":47.8,""taxRate"":19.0,""price"":251.6,""extensions"":[]}],""taxRules"":[{""taxRate"":19.0,""percentage"":100.0,""extensions"":[]}],""positionPrice"":232.0,""rawTotal"":299.4,""taxStatus"":""net""}"\n'