I am reading a PostgreSQL, and would like eventually to convert this into a nice JSON. The output from the PostgreSQL query contains e.g. "Decimal('value')" which I am trying to clean away. Unfortunately the values disappears during this process, and I am not sure how to re-write it so they remain.
Code:
columns = ("parameter", "timestamp", "epoch")
inputRecords = []
for row in cursor.fetchall():
inputRecords.append(dict(zip(columns,row)))
inputRecordsCleaned = [tuple(str(item) for item in t) for t in inputRecords]
inputRecordsJson = json.dumps(inputRecordsCleaned, indent=2)
Output:
inputRecords = [{'parameter': Decimal('-0.9'), 'timestamp': datetime.datetime(2020, 3, 11, 12, 16, 48), 'epoch': 1583929008}]
inputRecordsCleaned = [('parameter', 'timestamp', 'epoch')]
Expected Output:
inputRecordsCleaned = [('parameter': '-0.9', 'timestamp': '2020, 3, 11, 12, 16, 48', 'epoch': '1583929008')]