Need help with writing to json file

I am new hare , need some help with writing to json file:

I have a dataframe with below values
col1 col2
0 1
1 2
2 3

need to write this to json file with object as column dtls

Output :

[“Column Details”
{
“col1”:1,
“col2”:1
},
{
“col1”:2,
“col2”:1
},
{
“col1”:3,
“col2”:1
}
]

Please help.

Your desired output is not valid JSON. However, you can use pandas.DataFrame.to_json(orient="records") to get a JSON object that is quite close to what you want.