Forum Academy Marketplace Showcase Pricing Features

Convert text to json object & access object keys in bubble

Hey there,

I feel this is a very special case but nevertheless I hope that somebody can help.
Following situation:

I have a repeating group in my bubble page that gets data from a call to a MySQL Database. In this database there is a column called “config”. It contains ‘text’ although it’s actually structured as a json (this has different reasons).
The config column contains f.e. this:

{
"roomname":"SUITE",
"roomtypecode":"SUI",
"roomnameshort":"SUI",
"maxoccupancy":"2",
"minoccupancy":"1",
"separatebeds":"No",
"numbersepbeds":"",
"room_picture": "https://i.imgur.com/hSzdKAB.jpg"
}

In the repeating group I want to show the room_picture.

Currently I’m doing it by some complicated extract with regex function of "room_picture":.* and then search & replace for " and ,
It’s working, but it’s just not a nice solution and very error-prone.

As the config is basically a json object, I was wondering if it’s possible to access the object-values? So can I somewhere assign an object somehow like

const objectFromMySQL = config

So that in the repeating group I can then access the object via:

objectFromMySQL.room_picture

I’m not that experienced in bubble yet, so maybe there is a super easy way to do it. I only have the “javascript way” in my head and it’s hard to adapt to the bubble structure.

I also would like to have it that way to be able to have a conditional that hides the roompicture field, when objectFromMySQL.room_picture is empty (when there is no picturelink) or even shows a text like “picture not available”.

With the RegEx structure I cannot create this condition (always getting an error that it’s not a list).

Looking forward to your help and hope it was understable.

Josi

1 Like

Hey!

This one might help you:

Uh, thank you very much.
sounds lika good workaround.

Only thing I realised - that’s only working for the bubble plugin, right?
I built in Bubble App. Actually, what is the difference between them? I’m a bit confused and afraid, that I should’ve built it as a plugin.

Can you help here?
Thanks in advance!

1 Like

Hey!

In that case, you need to create a small Bubble plugin - and then use it in your Bubble app.