Format output as json serializable data python

Viewed 19

I have a function which gives output as a list of <class 'OSProcess'> which is not JSON serializable.

So when I'm trying to send the data back to the front-end, I have to use json.dump(output,default=str) which makes the format messed up even after using json.loads() This is the format that I currently am using:

[
    "{\n    'name': 'jstart',\n    'description': 'J2EE Server',\n    'dispstatus': 'SAPControl-GREEN',\n    'textstatus': 'All processes running',\n    'starttime': '2022 09 14 11:20:10',\n    'elapsedtime': '3:22:37',\n    'pid': 29723\n}"
]

I want the output to be in the below mentioned format so that it can be easily accessed on the front-end:

[{
    'name': 'jstart',
    'description': 'J2EE Server',
    'dispstatus': 'SAPControl-GREEN',
    'textstatus': 'All processes running',
    'starttime': '2022 09 14 11:20:10',
    'elapsedtime': '3:06:54',
    'pid': 29723
}]
0 Answers
Related