How would you handle a nested JSON object within a JSON object in an API workflow? (Saving response data to database)
- “result”: [
- “files”: […] <<<<< nested in results
//inside of nested files
- “files”: [
figured out my own problem.
Thanks for helping others with the same problem too!
@axeljaworski do you need help?
I am having a really hard time with this as well. How did you end up accessing the nested object and write it to the database? Thanks in advance!
Accessing it and writing it to db can be natively done thru bubble. Just make sure you’re initializing your calls and it’ll map the JSON response object for you. Then, after a call workflow to the api, you’ll have your create a new thing after, and you’ll be able to access the call data with “Result of step 1’s api calll” etc. Does this answer your question?
Have you tried this recently? I’m not able to access the nested objects. Bubble seems to only parse out the top level objects, but the data I need is nested inside “error body”. Bubble only allows me to set this to text. This means to extract the data, I need to use regex, which is not ideal.
In the screenshot, you see the nested object, and how I’m unable to access it “id”.
I too have this problem, and it appears that Bubble can’t parse nested JSON—it only works with the top level. I opened up a ticket with Bubble Tier 2 support about this, and it confirmed my fears. This doesn’t seem right—why can’t Bubble natively traverse the JSON data?
From the support rep:
"…After reviewing your case and screen recordings further, from my understanding, it appears that you are hoping to extract the “message” from the body of what is returned from the error.
If this interpretation is correct, have you considered utilizing the :extract with Regex operator? This operator allows you to return a specific part of an entry from a text using a Regular Expression (regex). We recommend using a Regex builder to test your expressions before using them in Bubble.
If I have misunderstood what you’re hoping to achieve in any way, or if I can offer any assistance with this implementation, please do reach back out and let me know; I’m always happy to help! "
They do natively traverse JSON, nested JSON, and heavily nested JSON
@doug.burden That’s what I want to hear. I found a solution to my problem, which I assume is a bit peculiar…
One of the nested JSON objects I wanted to traverse or access, “body,” in this instance was empty when a normal 20x code is returned. A 20x code is required to “initialize” an API method. However, when the response is not a 20x, “body” has valuable data—but it’s not possible to initialize a method if it doesn’t return a 20x. That’s a problem.
Fortunately, there’s a workaround, I noticed the ability to manually enter an API response, so I filled up that “body” field with the JSON not typically sent with a 20x response, and that worked.
I’m able to get the response, access the nested data, and write all objects as things in the database through Schedule API workflow on a list.
My problem is that I can’t seem to figure out how to put those objects back together into a nested structure in the database because, using scheduled workflows, you don’t know which objects get created first, so when running a Make Changes to a Thing to add the created objects to it, Do a Search For might turn up empty as those objects may not have been created yet.