Covert bubble object into JSON

Heyy

I’m creating a prompt-builder app in Bubble (screenshot below) and I want to save each prompt as a JSON in addition to the normal fields. My page lets a user pick or add values for:

  • Style
  • Quality
  • Shot type
  • Environment
  • Lighting
  • Camera angle
  • Effects
  • Characters (each with fixed traits + flexible features)
  • Free-form custom variables

The idea is → when the user hits Save – > Bubble creates or updates a Prompt thing and also writes a json text field that looks something like this:

{
  "title": "Neon portrait",
  "variables": {
    "style":    [{"value":"baroque painting","weight":1}],
    "lighting": [{"value":"rim light","weight":1}],
    "custom":   [{"key":"mood","value":"rebellious","weight":0.8}]
  },
  "characters": [
    {
      "name":"Luna",
      "fixed_features":{
        "gender":{"value":"female","weight":1},
        "eye_color":{"value":"green","weight":1}
      },
      "flexible_features":[
        {"category":"hair_style","value":"pixie cut","weight":0.9}
      ],
      "pose_action":"sitting on sofa"
    }
  ]
}

Question

  1. What’s the cleanest way to assemble this JSON in Bubble?
  • I tried the :formatted as text trick in a “Make changes to thing” step - kinda works, but the expression is huge, plus I’m not sure how to handle extra variables.

Happy for any help:) Thanks!

format as text are for the list (like list of default prompt optionses) and the rest are directly encoded in JSON

{
  "title": Current page item's title:format as json-safe,
  "variables": {
    "style":    [Current page item's style:format as text]
... 
}

I’m not sure I understand what you are saying

I use current page item because I don’t know how you have set thing for user. But it could be Parent group or something like that.
Can you share what you have set before using the format as text

I realised the arbitrary text won’t work because I have dynamic number of variables so I’m looking for some other solution:)

What do you mean? Is it that some of the objects in the JSON array will have different key value pairs or that some of the objects will have empty values, but all objects have the same keys?

Depends on use case. If just want text can use the format as text operator. If you want to use the JSON for something in bubble via dynamic expressions, you’ll likely just want to use the JSON as an API object.

In my apps I use my paid Plugin Data Jedi and I create API Objects from the JSON so I can just save to the Bubble database the API Object as a field, rather than needing to save a large JSON array as a text field.

When converting JSON into an API Object you can also designate keys as specific types of data like Option Set Values…so in your app, you wouldn’t need to save all the different fields you have in the screen shot, and instead would just have one field that is an API Object.

But I am still not sure when you mention ‘variables’ what you mean.

You can just do this by creating a dummy Get call or using Postman, right?

I have set it up like this

Result of step1 is not a list. What is it exactly? Can you share the content of this?

How can I pass the Bubble object into the dummy API call?

To create a data type that is an api object (listed under plugin types) you can create the dummy get call in api connector. That gives you a data type that can be used to save as a field in the bubble custom data type. That api object data type can also be used in dynamic expressions and do absolutely everything else custom data types can inclusive of triggering database trigger changes off the key value of one of the objects, even if the field is a list of the objects.

Is there a single downside to doing this rather than using lists/text in a 1:1 way? I guess privacy rules? When you download it as a .CSV from your database, is it just stored as JSON?

Privacy Rules are applied to a custom data type, so if your objects or json text are stored as a data field, apply appropriate privacy rules.

Downloading via Bubble I think it is downloaded as .csv if you select download as CSV and if you select download as JSON it would be JSON. Have a play around with the Export function in Bubble database, it gives you those two choices and one other. But any api objects stored on a field, I think come out via Bubble as ‘data from api connector’.

But there are ways to get those api objects out. I have a simple feature on Data Jedi plugin that allows you to export into 5 or 6 file types and the api objects come out properly, however, I have not tested it out on api objects saved to a data field, only the api objects loaded into the Data Jedi element. I’m planning next month to round out features for export and download of data and think I’ll be implementing it into the Data Jedi Plugin Paginator element so can download specific sets pages of data.

Figured there would be a catch…

Just something that requires the right tool for the job.

I’m working through a similar issue right now, I’m trying to debug my data saved to the DB but it’s only exposed as “Data from API connector” and I need to see the raw json. It’s a bit annoying that bubble hides this behind their api response schema. A simple solution would be to let us click on that and view it in the api schema map popup from the api connector

You can see the raw JSON if you set this feature in API connector (with header and error, both need to be enabled). You will be able to save the raw JSON into a text field.

So create two fields, one for the raw json and one for the API object. I might have to start using API objects in the future.

Everybody will be, a lot already are, a few have been for years.

If interested in using API Objects more, please upvote this idea HERE to enable the use of Bubble API to accept api objects for create and modify api calls to the Bubble app. It is the only thing we can not do that we can not solve on our own and need Bubble to implement. Without this we still must rely on the Create a New Thing or Modify a New thing actions (1.62 WUs on average) instead of the POST and PUT calls of API that do the same thing for around 23% less (API call create and modify are only around 1.25 WUs on average).

That would be awesome, somebody might build a chrome extension for it. For now, I just add to my admin page a section to sort and filter those. Normally I prefer to not build anything I do not need, so rely heavily on the app data tab to check on data, but in this case it is not possible, so I just build a simple UI for it.

Does the bubble data api support creating / modifying fields stored as data from api connector? I would imagine if it’s not supported from the api connector it wouldn’t from the data api