I need to decode and load to a DB, a string which arrives in the following format:
"[{u'date': 1508760000000, u'value': 0}, {u'date': 1509364800000, u'value': Decimal('5.989999771118164')}, {u'date': 1509969600000, u'value': Decimal('5.989999771118164')}, {u'date': 1510574400000, u'value': Decimal('9.579999923706055')}]"
Currently, this is the code I use in order to turn it into a dataframe:
import pandas as pd
import json
#json for example:
my_json="""[{u'date': 1508760000000, u'value': 0}, {u'date': 1509364800000, u'value': Decimal('5.989999771118164')}, {u'date': 1509969600000, u'value': Decimal('5.989999771118164')}, {u'date': 1510574400000, u'value': Decimal('9.579999923706055')}]"""
my_json=my_json[1:-1]
my_json=my_json.replace("u'","'")
my_json=my_json.replace("'",'"')
my_json=my_json.replace('Decimal("','')
my_json=my_json.replace('")','')
my_json=my_json.replace(', {','~ {')
my_json_list=my_json.split('~')
my_dict_list=[json.loads(row) for row in my_json_list]
df=pd.DataFrame(my_dict_list)
Is there a shorter/more elegant way to perform this?