I have a string representation of a dictionary. It's a nested dictionary, even more complex, of which the record_time
key has a datetime value like below:
d = """{
"motion_measure": {"INCAR": 69, "RANDOM": 63, "UNKNOWN": 62, "BIKING": 57, "WALKING": 48, "RUNNING": 41, "SEDENTARY": 0},
"samples": [0, 1.1791444, 11.036073],
"record_time": datetime.datetime(2018, 3, 26, 10, 3, 17, 441000)
}"""
I tried two methods as suggested in this related question:
import ast
ast.literal_eval(d)
ast.literal_eval
doesn't work because it can't handle the datetime value.
import json
json.loads(d)
json.loads
doesn't work either because datetime format is not deserializable.
Does anybody know a good way to convert it back into a dict or json using Python? I got this strange record format from OrientDB.