Forum Academy Marketplace Showcase Pricing Features

[NEW PLUGIN] Generate deep nested JSON from thing(s)

PLUGIN PAGE

jsoNest lets you generate deep-nested, highly-customizable JSON data from a thing or list of things. Runs server-side for use in api-workflows. This allows you to get database items, their associated items, their associated items, etc. and format the data as nested JSON. jsoNest does this by recursively looking up associated item types, expanding the data and nesting it.

jsoNest also lets you perform rich formatting including renaming bubble-assigned keys from the and reformating their values.

Dates - Bubble ISO date to other formats.
Currency - numbers to USD 2 -> “$2.00”.
Strings to booleans (i.e. “color” : “blue” becomes “color” : {“blue” : true).
Boolen to strings (i.e. “archive?” : true becomes “archive” : “true”

Great SendGrid companion or other services that do not convert data types or interpret conditionals besides booleans.

Things to note:
The plugin cannot recursively do a search for… xxx = current thing, so your database structure must have all the relationships able to map from the first item you are searching for. Its a bubble limitation, as best as I can tell.

Enjoy!

EDITOR

DEMO

12 Likes

This will come in handy! Thanks!!

Hi, it seems that your editor link is broken. Thanks for sharing!

I’ve gone ahead and made it public again. Thanks for the feedback!

Thanks @jon2,

Your plugin will be great to generate the json commands file needed by Jasonelle to create native app with Bubble in less than 10 minutes! :slight_smile:

1 Like

@jon2 Thank you very much ! I’ve tested every json generator so far and yours is the most powerful.
Nice to see such a power tool made available for free to the community

by the way, what do the checkboxes “intend” and “output logging” do ?

indent
the number of spaces you’d like to use (if any) for pretty output formatting of your JSON

output logging
This will print a log just before the JSON from the plugin’s output string. Useful when troubleshooting and if you don’t want to muck around in the server logs. I mainly used this when developing the plugin to speed things along. Realistically, you shouldn’t need this unless you are getting unexpected behavior.

Hi @jon2 What about when you just need an array of a specific field from a nested thing ?. Let’s say for example,
custom.order / custom.item
For the output one just need customization_text as this :

[
     {
           "phone_text": "(212) 555-1212",
           "tax_number": 1,
.... ,
   "items": ["Initials = A.S.", "Initials = J.S.", "n/a"]
....

and not the full list of fields of the “items”. ?
Is it possible to modify the config json file to do that? or it has to be done in the plugin ?

Hmmm…
The plugin can handle a list of things in bubble and returns an array of javascript objects. If I understand what you are asking for then it does not have that capability. I’ve proposed a workaround solution below.

Simple solution:
Store the text value of multiple child Items as a single list of texts inside parent Order. Do this just prior to running the JSONator workflow action.

Workflow
Step 1 Update thing

This Order
List of Customization Texts = Order's Item's Text (returns a list of texts)

Step 2 Run Jsonator

Input Thing:
This Order

Output JSON:
Order{
"list_of_customization_texts":[
"Initials = A.S.",
"Initials = "J.S.",
"Initials = n/a"]
}

Advanced Solution

If you don’t want to write to your db or have other needs that the above cannot provide, try this.

In JSONator you can delete any key:value pairs from your output JSON by including the line new_id : null to your configuration JSON for that key. The most succinct JSON expression you’ll be able to get from the plugin (by individually selecting every other key and deleting it) is an array of objects expressed as:

"Items":[
{"customization_text":"Initials = A.S."},
{"customization_text":"Initials = "J.S."},
{"customization_text":"Initials = n/a"}
]

I’d say give the below a try since I don’t know when I’ll get to adding this feature.

How to take an array of simple JSON objects and convert into an array of strings:

Once you’ve cleaned up your JSON to only show the field you want to turn into an array of texts, you’ll have a predicable string to work with in bubble using find/replace.

Example:
“Items”:[
{customization_text":“Initials = A.S.”},
{“customization_text”:
"Initials = “J.S.”},
{“customization_text”:
“Initials = n/a”}]

First, find your beginning text

{customization_text":
and replace with nothing

Find your delimiter text
},{"customization_text":

and replace with ,

Finally, find your end text

"}]

and replace with
"]

Your resulting text should be:
"Items":["Initials = A.S.","Initials = "J.S.","Initials = n/a"]

Which is a valid array of strings you generated from your array of JS objects.

Be careful with find/replace to avoid changing similar keys and syntax. The more specific, the better. You may also give regex a try as this provides more programatic control over find/replace

Thank you very much @jon2 ! It is very appreciated you took the time to create and share this plugin and to answer to my request. I will use your advanced workaround. Please let me know if I can do something for you.

Happy to help. :slight_smile: What goes around comes around.

Also, depending on what you’re trying to do, you might also try the ‘whitelist’ option in the plugin configuration. This option causes the plugin to only return the fields you specify in the configuration. Might be quicker, depending on how many fields you need.

Yes, I’m using it. Thanks.

If anyone else needs it. For reference :

Correction : }," replace with ,"

Correction : "}], replace with "],

Finally for empty objects
Find {} and replace with nothing

1 Like

I’m trying to use this plugin but when I try to generate the JSON with a list of things, it only shows the_id and the _type. Anything else which is within that type is not showing up. Any reasons why?

Looks like i found why I am not able to generate the json as it should be.

My data is set as following

  • Main Data
    – Sub Data
    — a list of Main Data

Probably this is creating a loop. Is there a way where I can make this work without deleting the nested data list?

Hi there @steve5. Let’s use some common bubble database terminology so we’re speaking the same language.

data type
text, date, images, number, etc. (also called a ‘column’ in relational DB terminology)

custom data type
contains several different data types within it (also called a ‘table’ in relational DB terminology). When a custom data type contains another custom data type inside it that is a relationship in relational db terminology

thing
a single record in the db that is a certain custom data type (also called a ‘row’ in relational DB terminology)

So it looks like you’re pointing the JSONator plugin to a single thing of custom type ‘main data’. That ‘main data’ thing contains a single thing of custom type ‘Sub data’. That single thing ‘sub data’ contains a list of things of custom type ‘main data’?

If this is the case, that looped relationship between Main Data to Sub Data and back to Main Data again is a problematic db design. You’ll want to look into that. The only way to fix this with the plugin is to delete it as you said.

In either case, what’s the behavior you are seeing? is it timing out? the jsonator plugin should have a depth search limit to prevent infinite recursions, however if your db is large and your unorthodox db architecture requires JSONator to search through a lot of records, then its entirely possible that the plugin will reach the 10 second bubble server-side execution runtime limit and be terminated.

tl;dr
relational databases shouldn’t have ‘looping’ relationships.

1 Like

Hi there! I’m encountering the same problem as @steve5. However, I don’t have any looping data architecture problems. That said, I’m also new to JSON and not much of a programmer. Any thoughts on what else might be causing this? I am attempting to generate nested JSON for a type that has several levels of related subtypes.

On a related (and probably ignorant) note: How would I go about storing and querying the resulting JSON? I’ll be calling via the data api from an external service.

Thank you!

By way of additional context: I am attempting to output JSON in a format digestible by the chatbot service Manychat. You can see the appropriate format here. Essentially, I have a number of different, nested custom types that correspond to data types in Manychat.

I want to be able to create an external request within Manychat to pull in dynamic content via Bubble. I had attempted to do so via Bubble’s native API. However, using that method, I only seem able to call data for the principle type, not the associated sub-types. That’s not a tenable solution, and I’m hopeful your tool can help me.

Please let me know if I can provide additional context. I so appreciate your help and this great tool you’ve built!

1 Like

Sorry for the late reply. When trying to troubleshoot issues of ‘timing out’–which I believe is the issue you are facing–I would recommend setting the ‘depth limit’ in the plugin first to 1, then 2, 3, etc.

This will let you see at what depth it is that you are having issues and help you narrow down the issue.

For example:

If you have an app keeping track of grocery store customer’s purchases, you might have a fairly complex DB setup as follows

fruits — > produce —> store ----> region ----> company
fruits ----> cart ----> customer ----> family

if you find that it regularly fails between depth 3 and 4, then you know thats is where the problem lies. It could be between store and region or possibly customer and family

I’m going to assume that unless this is an issue where you’ve got looping db relationships in your DB (bad), then this issue may related to your database architecture, and not be resolvable with plugin settings. Bubble allows plugins a max of 10 seconds to run a server-side action and so if your query requires longer than 10 seconds to run, the plugin will fail to complete.

A big culprit can be if you’ve got several lists of things, pointing to other things, which in turn each have their own list of things etc. It creates an exponential amount of work for the plugin to search through. This is a common issue with any DB architecture and should be taken into account when designing your app before JSONator.

For example:
One single item with 50 related things, which in turn each have 50 related things of their own will produce 2500 records which JSONator must iterate through. This is all just for one single ‘top level’ thing. If you have of these 50 top-level things with this configuration, thats 50^3 (125,000) records that must be retrieved, iterated through with the plugin and returned in 10 seconds. This is sort of Computer Science 101 stuff, but may not be immediately obvious to someone who has not encountered this before.

If it turns out there is an issue with the code, I’d be happy to take a look, but I’d assume a db limitation before I’d assume that.