Openai Json Parsing

Hey Forum!
I am getting this structured response from my openai api. I want to filter out all the ingredients and put them dynamically into a text in a repeating group. I am new in bubble and need help. Thank you!

This is the openai response:
{
“id”: “chatcmpl-9yHd5M9B4n6Gb661uOxTBV15qI3HF”,
“object”: “chat.completion”,
“created”: 1724154475,
“model”: “gpt-4o-2024-08-06”,
“choices”: [
{
“index”: 0,
“message”: {
“role”: “assistant”,
“content”: “{"ingredients":[{"ingredient":"chicken (boneless, skinless)","quantity":"500 grams"},{"ingredient":"onion","quantity":"1 large, finely chopped"},{"ingredient":"tomato","quantity":"2 medium, pureed"},{"ingredient":"ginger-garlic paste","quantity":"1 tablespoon"},{"ingredient":"yogurt","quantity":"1/2 cup"},{"ingredient":"vegetable oil","quantity":"2 tablespoons"},{"ingredient":"cinnamon stick","quantity":"1 inch"},{"ingredient":"cloves","quantity":"4"},{"ingredient":"cardamom pods","quantity":"2"},{"ingredient":"turmeric powder","quantity":"1/2 teaspoon"},{"ingredient":"red chili powder","quantity":"1 teaspoon"},{"ingredient":"coriander powder","quantity":"1 1/2 teaspoons"},{"ingredient":"garam masala","quantity":"1 teaspoon"},{"ingredient":"cumin seeds","quantity":"1 teaspoon"},{"ingredient":"salt","quantity":"to taste"},{"ingredient":"fresh coriander leaves","quantity":"for garnish"}],"procedure":[{"step":"Cut the chicken into bite-sized pieces and set aside."},{"step":"Heat the oil in a large pan over medium heat. Add the cumin seeds, cinnamon stick, cloves, and cardamom pods. Sauté for a minute or until fragrant."},{"step":"Add the chopped onion and cook until it becomes golden brown."},{"step":"Stir in the ginger-garlic paste and sauté for another minute until the raw smell disappears."},{"step":"Add the tomato puree and cook until the oil begins to separate from the mixture."},{"step":"Mix in the turmeric powder, red chili powder, and coriander powder. Cook for a couple of minutes."},{"step":"Add the chicken pieces to the pan and stir well to coat with the masala paste."},{"step":"Pour in the yogurt, season with salt, and mix thoroughly."},{"step":"Cover and cook on low heat for about 20 minutes or until the chicken is cooked through and tender, stirring occasionally."},{"step":"Add garam masala and garnish with fresh coriander leaves before serving."}]}”,
“refusal”: null
},
“logprobs”: null,
“finish_reason”: “stop”
}
],
“usage”: {
“prompt_tokens”: 44,
“completion_tokens”: 419,
“total_tokens”: 463
},
“system_fingerprint”: “fp_2a322c9ffc”
}

You can use the :extract with Regex operator in Bubble with the Regex being
"ingredient":"([^"]*)","quantity":"([^"]*)"

This will return a list of your ingredients and corresponding quantity. For your example, this is what I get:

  • “ingredient”:“chicken (boneless, skinless)”,“quantity”:“500 grams”,
  • “ingredient”:“onion”,“quantity”:“1 large, finely chopped”,
  • “ingredient”:“tomato”,“quantity”:“2 medium, pureed”,
  • “ingredient”:“ginger-garlic paste”,“quantity”:“1 tablespoon”,
  • “ingredient”:“yogurt”,“quantity”:“1/2 cup”,
  • “ingredient”:“vegetable oil”,“quantity”:“2 tablespoons”,
  • “ingredient”:“cinnamon stick”,“quantity”:“1 inch”,
  • “ingredient”:“cloves”,“quantity”:“4”,
  • “ingredient”:“cardamom pods”,“quantity”:“2”,
  • “ingredient”:“turmeric powder”,“quantity”:“1/2 teaspoon”,
  • “ingredient”:“red chili powder”,“quantity”:“1 teaspoon”,
  • “ingredient”:“coriander powder”,“quantity”:“1 1/2 teaspoons”,
  • “ingredient”:“garam masala”,“quantity”:“1 teaspoon”,
  • “ingredient”:“cumin seeds”,“quantity”:“1 teaspoon”,
  • “ingredient”:“salt”,“quantity”:“to taste”,
  • “ingredient”:“fresh coriander leaves”,“quantity”:“for garnish”

This topic was automatically closed after 70 days. New replies are no longer allowed.