I am calling the OpenAI Chat Completion API and requesting it to return in JSON format. I am asking OpenAI to write a list of user stories for me, and return the list in JSON format separating the user story title and description.
My goal was to save each user story in a different Bubble DB row, saving the title in one column and the description in another.
However, even if I ask OpenAI to return in JSON format, it all comes back within the “content” property, and Bubble doesn’t recognize the other properties OpenAI used to distinguish the title and description of each user story. Below is an example of what I am getting back from OpenAI:
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": xxx,
"model": "xx",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "{\n \"user_stories\": [\n {\n \"id\": 1,\n \"title\": \"User Identification Step\",\n \"description\": \"As a pet owner, I want to identify if I already have a pet and provide its details (dog or cat), name, postal code, email, and consent so that I can get a quote.\"\n },\n {\n \"id\": 2,\n \"title\": \"Conditional Navigation for Pet Ownership\",\n \"description\": \"As a user, if I do not have a pet yet, I want to provide a pickup date before proceeding so that I can give accurate information for the insurance quote.\"\n },\n {\n \"id\": 3,\n \"title\": \"Progress Bar Update\",\n \"description\": \"As a user, I want the internal progress bar to update when I tap on continue so that I can see my progression through the quote process.\"\n },\n {\n \"id\": 4,\n \"title\": \"Information Modal\",\n \"description\": \"As a user, I want to click on the Information icon to display a modal with more text and an option to dismiss it so that I can understand the details better.\"\n },\n {\n \"id\": 5,\n \"title\": \"Field Validation and Error Messages\",\n \"description\": \"As a user, I want to be prompted to fill all required fields and see error messages if my postal code validation fails so that my input is correct and complete.\"\n },\n {\n \"id\": 6,\n \"title\": \"Postal Code Validation Integration\",\n \"description\": \"As a user, I want the postal code validation to be integrated with Azure Maps and informed if my postal code does not exist so that I can correct it.\"\n },\n {\n \"id\": 7,\n \"title\": \"Opt-In Check Marks Configuration\",\n \"description\": \"As a product administrator, I want to configure which opt-in check marks are required, optional, or visible so that I can tailor the user consent options.\"\n },\n {\n \"id\": 8,\n \"title\": \"Email Format Validation\",\n \"description\": \"As a pet owner, I want to receive basic email format validation when I fill in my email so that I ensure my email is in the correct format.\"\n },\n {\n \"id\": 9,\n \"title\": \"Provide Relevant Information About the Pet\",\n \"description\": \"As a pet owner, I want to provide relevant information about my pet so that I can get an accurate insurance quote.\"\n },\n {\n \"id\": 10,\n \"title\": \"Display Pricing\",\n \"description\": \"As a user, I want to see the pricing of the insurance policy so that I can make an informed decision about the purchase.\"\n },\n {\n \"id\": 11,\n \"title\": \"Complete Purchase\",\n \"description\": \"As a user, I want to complete the purchase of the insurance policy so that I can insure my pet without any complications.\"\n },\n {\n \"id\": 12,\n \"title\": \"Generate Insurance Policy\",\n \"description\": \"As a user, I want the system to generate an insurance policy once the purchase is complete so that I have proof of insurance for my pet.\"\n }\n ]\n}"
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": xxx,
"completion_tokens": xx,
"total_tokens": xx
},
"system_fingerprint": "xxx"
}
I need to parse the content within “content”, to save each individual “title” and “description” as a separate entry in the DB.
Any ideas on how I could accomplish this?