Forum Academy Marketplace Showcase Pricing Features

Parsing RAW JSON best practices?

Take a look at this:

"{\"costs\": {\"Total Cost\": 0.0, \"Delivery Cost\": 0.0, \"Total Discount\": 0.0}, \"variables\": [{\"ID\": 3, \"Store\": 1, \"Type\": 1, \"Individual discount\": 0.0, \"Store discount\": 1.0, \"Individual delivery discount\": 0.0, \"Store delivery discount\": 1.0, \"Quantity\": 1.0}, {\"ID\": 19, \"Store\": 1, \"Type\": 2, \"Individual discount\": 0.0, \"Store discount\": 1.0, \"Individual delivery discount\": 0.0, \"Store delivery discount\": 1.0, \"Quantity\": 1.0}]}"

This is what’s outputted as text and stored in my database. Not an issue. Now I need to parse it and turn each ID into a unique thing in the database. I’ve already brain stormed that this is fact possible with regex - but, is it possible another way? Perhaps a plugin?

To summarize, I need to create an object out of each ID, with each object having the pertaining information relative to its ID. This can be accomplished with Regex, but is there an easier way?


It would be really quick to make a plugin to organize this in a manner then pass it back to bubble all ready to be added to the database. Can you show me the fields for the data type you are hoping to create and I can throw one together. I will make it open source so you can see the code.


That’s awesome!

We’re looking to store each ID.

Each ID would have the values:
-Individual Discount
-Store discount
-Individual delivery discount
-Store delivery discount

Hope this helps! Let me know if you need something else!

1 Like

The plugin is called JSON.parse()

Here is an example:

Here is the editor:

1 Like

Wow this is very awesome!!

I can’t seem to install it on my application - would I be able to pay you?

1 Like

Maybe it just hadn’t showed up in the marketplace yet but it is there now.

1 Like

Thanks so much for putting this plugin together. I was looking for something like this last week. I looked at the App Data and the element workflows in the Editor and didn’t see how you looped through the rows in the RG to save each entry into the database.

I see use of a custom state (still learning the Bubble use of that), but not how you saved each row. Would I have to use a backend workflow to process the state value? (I’m trying to do something similar for a set of bookmarks. I processed first in regex, which works, but want to try JSON – but can’t figure out creating a separate entry for each item.)

The workflow’ ‘JSON.parse variable has been retrieved runs for each variable in the JSON object. On the bubble side it appears it is set up to just create one item but that workflow is triggered within a loop so it will occur multiple times at 100 milliseconds apart. On each iteration the values of the states of the element are updated and then the variable retrieved event is triggered.

So the plugin is not looping through the repeating group but it is creating the data that is displayed in the repeating group. If you pass in a string of four variables then ‘JSON.parse variable has been received’ will run four times and four items will display in the repeating group.

You can fork this code into your own plugin and make it more dynamic. For instance if you gave the plugin element like 10 text fields you could just type in whatever the objects keys were named and then reference those in the loop and it can pull data based on the structure of the JSON string you pass in.

1 Like

I appreciate the response. I saw earlier how a single item is being created in the database, but not entirely sure how the loop is integrated. It’s most likely because I’m not yet familiar with how to set up loops in Bubble. (Although I do see the page view + 1 setup; will study further.) Once I find how to fork a Bubble plugin, I’ll try it out for my bookmarking case. Thanks once again for this plugin. (I’m originally a Web developer myself, but still learning how to think and do in Bubble.)

EDIT: The fork button for your plugin seems to be grayed out for me. Maybe I need to upgrade from a free account first.


So this isn’t customizable for our individual scenarios? I noticed that when I placed the element on the page it has all your custom states shown on your example page. I also don’t know how to make my own plugin.


If you go to the plugin page and click the ‘See the Code’ button, you will be able to see the ‘states’ and fields I used and this will give you an idea of what you need to change to match your needs. Once you feel like you know how to change it then click the ‘Fork’ button on the same page and you will have your own copy of the plugin that you can edit. Just make it ‘Private’ on the Settings tab and add your app as an authorized app. I didn’t take too much time to explain in detail what everything is doing, but I feel like anyone without any coding experience could be able to look at the finished product and the code to determine what should be changed for their use case.

1 Like

Thank you for this explanation. Now I know how to Fork.

Hi @williamtisdale,

It seems this isn’t as easy of a process as it sounded. I now understand what variables/states that I need to change, but I don’t understand the forking process. Do I need to use GitHub? Also, the Fork button on the plugin page is disabled. Will you help me out here?


I’m not sure about the forking process to be honest. Maybe it would be easier to open the plugin code side by side next to a new plugin and just copy everything over as it isn’t much.