Returning Option Sets via Workflow API or building complex JSON for API returns

For anyone who may run into issues with API calls, I had a specific instance where I needed to get all the option sets and attributes all in one call (the attributes made it a bit tricky).

I was able to use this plugin (no affiliation to author) -
[JSON Creator (Frontend & Backend) Plugin | Bubble] to solve this issue.

Specifically I have an option set, and each option has a list of attributes, and possibly other attributes to append. This was challenging because of Bubble’s limitation of “not being able to add a bunch of stuff to individual stuff” - Once you go down to thing of thing you’re stuck at thing of thing.

The option set description below.


The JSON response i wanted is. (a standard return style response from bubble workflow API.

{
  "status": "success",
  "response": {
    "Flower Types": [
      {
        "Display": "Lillies",
        "Colors": [
          "White",
          "Blue",
          "Purple",
          "Fuschia"
        ],
        "size": "4-8\""
      },
      {
        "Display": "Sunflowers",
        "Colors": [
          "Yellow"
        ],
        "size": "8-16\""
      },
      {
        "Display": "Daisies",
        "Colors": [
          "White"
        ],
        "size": "2\""
      },
      {
        "Display": "Rose",
        "Colors": [
          "Red",
          "White",
          "Yellow"
        ],
        "size": "3-4\""
      },
      {
        "Display": "Tulip",
        "Colors": [
          "White",
          "Violet",
          "Red",
          "Yellow"
        ],
        "size": "3-4\""
      }
    ]
  }
}

And the steps using this plugin were

  1. Create object with simple text field.
    image
  2. Create empty object
  3. Create array From List and append it to the empty object using the below screenshots settings to essentially format the JSON.

    3.a - The inner format as text was the array text separated by commas (,) for the array list.
    image
    3.b the find and replace was to escape the double quotations (")
  4. Append the newly created object from step 3 to to the initial created object in step 1.
  5. Return the plain text.

This isn’t perfectly formatted JSON as it doesn’t include all the carriage return types and tabs, but any JSON parser handles it fine.