Working with JSON objects in a returned value in API Connector

The API connector has this annoying quirk.

Any response values that contain a single JSON object can only be matched to a text type instead of a JSON object. This makes it a little annoying to deal with. Easy to parse on the frontend but annoying when dealing with these kind of things server-side.

What I realized is that if that JSON object was returned as part of a JSON array, it is detected as a JSON object. Which I can then match individual values of the object to datatypes and access it as part of a list in that array.

There are workarounds like passing payloads through custom events to parse JSON objects.

For my use case the workaround is to make sure that the single JSON object is stored in a JSON array. Of course, the catch is that you must have control of the payload response. Using a CF worker as middleware can enable this.


I’m posting this as a note to myself but hope it helps others. Feel free to ask questions or share your thoughts.

3 Likes

This is not true. The reality is that the API really return a text string. Yes the content in the end is a JSON (escaped), but this is not a JSON object… this is a string. If this was an Object, this would have been parsed by Bubble.

You can workaround this by sending it to a backend WF with API connector, but this only work if the JSON returned always have the same structure.

1 Like

Hmm…I’m pretty sure I’m sending a JSON object from my endpoint. Will check this out!

1 Like

You can share the API Connector response screenshot (both parsed and raw data)