Need help displaying data from nested JSON

I am currently using OpenAI to send back a template for training via a json format. However, it’s well known that using the assistant api doesn’t actually send back the json in a readable format on the first go, I believe it captures the full response as “context”. Anyways, once generated, I take this json in the response and save it as a text data type in my bubble app.

I am desperately trying to display different parts of this json in a clean way but am running into issues with each approach.

  1. Regex - This is just not clean and the complexity of nesting doesn’t allow for regex to be a viable option.
  2. Using a json parser plugin like JSON Machine to display the information needed. However, once it gets to a nested section, then it doesn’t display anything but “[object], [object]”
  3. Running a backend workflow on a list. I tried setting up a BE WF to take the original “context” that I’m saving in my database as text, running that through an internal api to parse the json, but having difficult saving the data correctly now. I think this is the best option, but also most likely the most costly when scaled.

Here’s an example JSON response where I struggle to successfully save the Weekly routines and drills under the correct sections.

{
“golfer_details”: {
“name”: “Tiger Woods”,
“age”: 35,
“gender”: “Male”,
“skill_level”: “Expert”,
“strength”: “striking approach shots with 56, 52 and pitching wedge”,
“weakness”: “long irons, hybrids, driver (thin hits, chunk hits, or slicing right)”
},
“training_schedule”: {
“frequency”: “2 days per week”,
“session_length”: “45 minutes”,
“start_date”: “2024-03-01”,
“end_date”: “2024-03-31”
},
“weekly_routine”: [
{
“day”: “Tuesday”,
“focus”: “Iron Contact and Accuracy”,
“drills”: [
{
“name”: “Low Point Control Drill”,
“description”: “Practice hitting balls with a focus on controlling the low point of your swing to ensure contact with the ball first.”,
“equipment_needed”: [
“irons”,
“golf balls”,
“turf mat or driving range”
],
“repetitions”: “5 sets of 5 shots”
},
{
“name”: “Alignment Stick Drill”,
“description”: “Place alignment sticks on the ground to ensure proper foot alignment and target line. Focus on striking balls with your irons while maintaining this alignment.”,
“equipment_needed”: [
“irons”,
“alignment sticks”,
“golf balls”
],
“repetitions”: “4 sets of 5 shots”
}
],
“tips”: “Focus on the consistency of your ball striking. Ensure you’re hitting the ball first, then the turf.”
},
{
“day”: “Friday”,
“focus”: “Driver and Hybrid Control”,
“drills”: [
{
“name”: “Tee Height Drill”,
“description”: “Practice hitting drives off a tee with different heights to improve the launch and reduce slicing. Focus on making solid contact at the correct part of the club face.”,
“equipment_needed”: [
“driver”,
“golf tees”,
“golf balls”
],
“repetitions”: “5 sets of 4 shots”
},
{
“name”: “Hybrid Control Drill”,
“description”: “Take practice swings with your hybrid focusing on maintaining a slow and controlled tempo. Then try hitting balls with the same tempo.”,
“equipment_needed”: [
“hybrid clubs”,
“golf balls”,
“turf mat or driving range”
],
“repetitions”: “5 sets of 4 shots”
}
],
“tips”: “Work on your grip, posture, and alignment to reduce thin and chunked shots. Improve consistency with your hybrids and driver to control ball flight.”
}
]
}

Any suggestions?

Yes try doing this. You use the API Connector (or maybe App Connector) to trigger your backend workflow and let it parse everything

I’m mostly there, but stuck on this last part (I believe). @tylerboodman are you able to point out what’s going wrong here?

  • For Testing purposes, I stored the json that I copied in my original post in a data type called ‘SessionJSONS’ under ‘messagecontent’. There is only one row of data for this.

  • I have a test page setup to where I click a button and it triggers this workflow:

  • Here’s the backend for convertdb workflow and the api connector settings - All it does it searches for the json in the database then passes the text through as a json.


  • Step 2 of the button’s workflow is to create a ‘testtrainingplan’ and step 3 triggers the backend api to create the weekly routines from the json (the nested data)


  • Moving to the backend workflows for API Call weekly_routine
    Settings:


    Step 1: Create a new weekly routine data type. I tried two different approaches to see which one would work for adding the focus or the weekday thinking if the api is run on a list of things, and this is the first weekly routine in the list, it shouldn’t matter, but we’ll see at the end that neither approach worked.

Step 2: Add the weekly routine to the training plan that we previously created on the front end and passed through to this api.

The results:
A training plan was created successfully and 1 of the two expected weekly routines was created successfully and linked to the training plan. However, as mentioned, it only created 1/2 weekly routines, and it also did not update focus or weekday for these weekly routines.
Training plan record:


Weekly Routine records

Any help would be appreciated. Let me know if you need any additional information as well. Thanks!

Anthony, not following all the steps exactly but if it’s a list of texts that you want to run the API WF on, the parameter should be “This text” (see arrow in image)

Hi thanks for the reply. I’m not sure I understand your suggestion to change that parameter? That’s simply just the training plan that I’m creating to link the weekly routines to. The list of “texts” that I want to run the API WF on is actually the Weekly’ routines section of my json. There should be two.

The training plan parameter is for the individual workflow so it should be “this Text” which will use the text from the current record in the WF from the List to run on but not the whole list

I’m sorry, but I’m still not following your suggestion. The training plan parameter is just that, a single parameter being passed in my workflow. I assume each list item would utilize the same training plan record, which is what I intend.

As for the list, in my screenshot for step 2 in my front end workflow, saving the training plan, I am saving the full JSON API response which has two “Weekly Routines” mentioned within it. That’s why in my settings for step 3 for List to run on, I am referencing the json’s (that I saved in the training plan) weekly routine. Is that not the correct approach?

Also, even though I didn’t follow your suggestion, I did try changing training plan to texts, but that is not an option.

EDIT To further add, the list is processing as it should considering it is in fact creating two separately weekly routines, so it’s picking that piece up correctly. I am just unable to save the information from these sections correctly.

What’s the List that the API WF is running on? It’s not a single record.

Whatever the list the individual API WF has to reference the specific single record from that list.

Thanks again for working with me here.

I seem to have figured it out. I didn’t need to update the training plan as you suggested, but I needed to add additional parameters to specifically send the weekly routine mentioned in that api call as a parameter for those fields I wanted to save. Thanks for pointing me in the right direction :+1:t2:

@code-escapee

Ok, so I got weekly routines saving as intended as I updated in my last message. However, I’m now having trouble saving the drills from each weekly routine.

Here is my updated api call on a list for the weekly routines:


That workflow worked well, so I figured I could replicate it to add drill data types then link them to the correct weekly routine type. I tried doing this by setting up a similar api call on a list as mentioned in step 3 here:

But it’s cycling through and creating duplicates and also not creating a single record per drill:



Hey not sure if this will help but I recently recorded a video on how to process a JSON response from OpenAI using the API Connector

Thanks Vlad - gave the video a watch but this doesn’t solve for my issue as the JSON that I’m working with has nested objects so I’m having a difficult time saving the lists of values that are three layers deep. Any suggestions for that?

Its still the same issue. If running a WF on a list, you have to specify the list and then for each item in the list you have to tell the WF where each parameter that the API requires is…

I’m passing the correct information for the list that I want it run on. However, I’m not doing it the way I’d like because right now I’m either getting

  1. Duplicate values for drill records being created, or;
  2. Each weekly routine’s drills added as a list of drills in one drill record, which is also being duplicated for each routine.

As I said you aren’t using the individual record’s data for parameters. You have to split the JSON into individual records OR iterate thru it as a loop until there is no more nested data

But howwww? lol I can only pass through the json 1x in the beginning which I’m doing by saving the api call to my test training plan type. From there the api’s don’t have an option to continue to send them. Or at least not from what I can see.

Thanks,

Anthony

You can split the JSON by certain parameter into a list of texts OR again iterate thru it as a loop peeling off the first value each time (this approach is NOT a API WF on a LIST it’s one text so a single API WF that is recursive until the JSON is empty.

I am very appreciative for you sticking with me here, and I hate to ask it, but could you please spoon feed this to me. While I understand the concept you are describing, I am at a loss for how to accomplish this. The JSON example in my original post is the exact one that I’m working with in my app, could you please describe step by step exactly what I need to do in order to accomplish this correctly?