I am using pandas library to read .csv file and to convert csv file to json using json library but in my csv file one column contains a list which I have to also convert into json array list but it is converting into a string format
here is my csv content
recipe_id | recipe_name | ingredients2 |
240488 Pork Loin [{"title":"basmati rice","quantity":"1 cup"},
{"title":"mint leaves","quantity":"1/2teaspoon"},
{"title":"salt","quantity":"as required"}]
218939 Foolproof [{"title":"Meat","quantity":"1 kg"},
Rosemary {"title":"Water","quantity":"1 Glass"},
{"title":"Mirch powder","quantity":"5 -10 Teaspoon"}]
this is my code
import numpy as np
import pandas as pd
import json
from flask import Flask, render_template
app = Flask(__name__)
df = pd.read_csv('sample.csv')
@app.route("/index")
def index():
data = pd.DataFrame(df[['recipe_id', 'recipe_name', 'ingredients2']])
return_data = data.to_json(orient="records")
prse = json.loads(return_data)
response = app.response_class(
response=json.dumps(prse, indent=4),
status=200,
mimetype='application/json'
)
return response
if __name__ == '__main__':
app.run(debug=True)
output:
[
{
recipe_id: 240488,
recipe_name: "Pork Loin, Apples, and Sauerkraut",
ingredients2: "[{"title":"basmati rice","quantity":"1 cup"},{"title":"mint
leaves","quantity":"1/2 teaspoon"},{"title":"salt","quantity":"as required"}]"
},
{
recipe_id: 218939,
recipe_name: "Foolproof Rosemary Chicken Wings",
ingredients2: "[{"title":"Meat","quantity":"1 kg"},{"title":"Water","quantity":"1 Glass"},
{"title":"Mirch powder","quantity":"5 -10 Teaspoon"}]"
},
]
expected output :
[
{
title: "Biryani",
description: "Chicken Biryani",
ingredients2: [
{
title: "basmati rice",
quantity: "1 cup"
},
{
title: "mint leaves",
quantity: "1/2 teaspoon"
},
{
title: "salt",
quantity: "as required"
}
]
}
]
pleas help me for this
ingredients2column contains thekey values and pairso i want to get that data in json array list as above i have mentioned please any help for this