Nested JSON Object

How would you handle a nested JSON object within a JSON object in an API workflow? (Saving response data to database)

example

  • “result”: [
    • {
      “id”
      “type”
    • “files”: […] <<<<< nested in results
      }
      ]

//inside of nested files

  • “files”: [
    - {
    “id”
    “type”
    “etc”
    }
    ]

figured out my own problem.

Thanks for helping others with the same problem too!

2 Likes

@axeljaworski do you need help?

1 Like

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!

1 Like

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?

1 Like

Thanks!

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.

Hey @doug.burden,

I wanted to know if you could lend a helping hand to a relatively new Bubble dev.

I have a JSON Object with nested fields that I’m trying to pull from the API call and the correct data is coming through from the request. The issue I’m having is that the field I want is nested and I can’t seem to pull the info I want, even though it’s right in front of my face when I initialise the call.

I wanted to keep it simple and basically call the GET Task request in a backend workflow, and then just send an email to myself with the nested field.

Inside the custom_fields (list), I want to extract the value where the custom fields name is “E-Mail-Adresse”.

“name”: “E-Mail-Adresse”
“value”: "rosschurch9+tuesday@gmail.com

Once I’m able to send myself an email with the correct value, then I can look at how to use it in a real life scenario. Let me know if you’d be able to help :pray:



UPDATE:

I have managed to pull every fields value in that object except the “value” field :frowning: I’ve attached images to show how I’m pulling the fields and trying to pull the value field.




Can you share the whole payload here please?

Hi all, I wanted to post how I came right with my problem above.

I first did a count of all custom fields in he JSON object, the response was: 40
I then did a count of all custom fields’ values in the JSON object, the response was: 2

I then went and found which 2 values were being recognised, and both of them were list item values, even if the value was just one list item.

I then made those 2 (multi-select) questions optional, did not answer them in my form and repeated the above steps (count of custom fields: 38, count of custom fields values: 38)

I reinitialised the call in the API-connector so that the request expected single values (even of different value types). Lastly I went and made the 2 multi-select questions required again, and it worked as expected, 40 custom fields, 40 values.

Thank you for your input on this post, I think isolating the issue and taking it step by step was what got me through,