I had been in my head over the past few weeks thinking about this as I’ve been using the bulk create more and more in conjunction with scripts…I figured it could just upload a csv to be recognized as JSON, can upload as many rows as the bulk create allows objects.
I love json assistant but it doesn’t quite do it the same…
I can do most of what I want to do but better with the run js,
If I want to go avascript to api data using json assistant I have to run the js, in the js I must stringify the result, then I must pass the bubble_fn sting to jsonata element, then I must wait for the jsonata element or potentially trigger off jsonata has changed. It’s not as quick and can cause race conditions.
Great too tho I still use for a lot of things
function(instance, properties, context) {
var fnNameSuffix = properties.fn_name_suffix;
var trigger_event = properties.trigger_event;
var publish_value = properties.publish_value;
var value_is_list = properties.value_is_list;
var queueActive = properties.queue;
var multipleoutputs = properties[“multipleoutputs”];
var useApiPrefix = properties.use_api_prefix; // New property for toggling prefix feature
instance.data.queue = ;
// New function to add API prefix to object keys
function addApiPrefix(obj) {
if (!useApiPrefix || !obj) return obj;
if (Array.isArray(obj)) {
return obj.map(item => addApiPrefix(item));
}
if (typeof obj === 'object') {
const newObj = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
const newKey = `_*api_*c2_${key}`;
newObj[newKey] = addApiPrefix(obj[key]);
}
}
return newObj;
}
return obj;
}
instance.data.fn_clearvalues = function() {
if (publish_value) {
instance.publishState("value_list", []);
instance.publishState("value", null);
instance.publishState("output1", null);
instance.publishState("output2", null);
instance.publishState("output3", null);
instance.publishState("output4", null);
instance.publishState("outputlist1", []);
instance.publishState("outputlist2", []);
instance.publishState("outputlist3", []);
instance.publishState("outputlist4", []);
}
}
instance.data.fn_publish = function(value) {
if (publish_value) {
if (multipleoutputs) {
const transformedValue = addApiPrefix(value);
instance.publishState("value", transformedValue?.value);
instance.publishState("value_list", transformedValue?.value_list);
instance.publishState("output1", transformedValue?.output1);
instance.publishState("output2", transformedValue?.output2);
instance.publishState("output3", transformedValue?.output3);
instance.publishState("output4", transformedValue?.output4);
instance.publishState("outputlist1", transformedValue?.outputlist1);
instance.publishState("outputlist2", transformedValue?.outputlist2);
instance.publishState("outputlist3", transformedValue?.outputlist3);
instance.publishState("outputlist4", transformedValue?.outputlist4);
} else {
if (value_is_list) {
instance.publishState("value_list", addApiPrefix(value));
} else {
instance.publishState("value", addApiPrefix(value));
}
}
}
}
if (fnNameSuffix) {
var fnName = "bubble_fn_" + fnNameSuffix;
window[fnName] = function(value) {
if (!queueActive || instance.data.queue.length == 0) {
if (publish_value) {
instance.data.fn_publish(value);
}
}
if (queueActive) {
if (publish_value) {
instance.data.queue.push(value);
} else {
instance.data.queue.push(null);
}
}
if(trigger_event && instance.data.queue.length < 2) {
instance.triggerEvent("event");
}
}
}
instance.data.fn_dequeue = function() {
instance.data.queue.shift();
if (queueActive && instance.data.queue.length > 0) {
if (publish_value) {
var value = instance.data.queue[0];
instance.data.fn_publish(value);
}
if(trigger_event) {
instance.triggerEvent("event");
}
}
if (queueActive && instance.data.queue.length == 0) {
if (publish_value) {
instance.data.fn_clearvalues();
}
}
}
instance.data.fn_clearqueue = function() {
instance.data.queue = [];
if (queueActive) {
instance.data.fn_clearvalues();
}
}
}
It’s claude generated
Yes you can do it direct but it doesn’t account for any errors or if you want to make changes to the data before sending it to bubble. The backend data bulk api saved a project for me, without it we would not have been able to offer the performance the client wanted.
I used jsonata (json assistant) a lot on this too to transform the data and do lookups, can be helpful
@chad5 @rjwilkinson10 @DjackLowCode @adamhholmes I just put together a free plugin that will do this.
It has it’s own action to run, or you can use the toolbox run javascript action. It has a single element that will publish as an API thing.
If you would like to try it out before bubble publishes it, please let me know and I can give access I think…I’m looking at plugin and editor and doesn’t seem possible to add more than one testing app or authorize apps (like if it was a private plugin).
The intended purpose of this free plugin is simply to take the json and append the _api_c2_
to each key in the json passed through either the plugins action or the toolbox run javascript action and to publish the value as the API type selected.
Here is run mode demo…Bubble | No-code apps
Nice one @boston85719 ! This is definitely opening up new ways to store + transform JSON.
Looks like it’s also possible to use the Expression element to render the JSON, which can be useful for when you don’t want to use workflows (e.g. JSON stored in state or on the data type itself, repeating groups etc.).
Here’s a simple example:
Looking forward to this potentially being part of Toolbox
Same here. I use JSON Assistant for everything JSON but I actually made a personal plugin to handle JSON to Type a couple weeks back. Added a sort by key feature so the list sorts based off any JSON key.
Been a real time saver.
Do you mean an actual Bubble type? I’m intrigued and curious about this as I have a use case for front end…I also wonder if @NoCodeDataArtisan could incorporate something like that directly into JSON Assistant.
Awesome work, exactly what I’m talking about.
I’ll check it out. I’m not sure I’ll move from toolbox plugin. I know @mishav hes an absolute awesome guy and I will use toolbox until the day I die
Misha helped me with my very first app back in 2016 when I needed to overcome an api that returned a different type of response than it said it would. He set up an intermediate service to get the job done.
Not just that but his toolbox plugin has over 700k installs, 100 of them are probably mine.
Thanks @mishav would love for you to implement if you have time.
Don’t have to
can use the toolbox run javascript…
if the requested feature is not implemented into toolbox can use the plugin of mine just for this specific purpose while still using toolbox for the run javascript or use the approach from @DjackLowCode and use expression element from toolbox as it is same basic concept of append the _api_c2_
to each key in the json.
What is cool about @DjackLowCode approach is no need for an action to run.
I’ll be adding into the plugin a server script to do it in backend and likely a built in parser to find values between two sets to determine which exist in DB already and which do not, as well as determining if a single value has been updated or not in order to determine if it needs to run through the bulk create to add new ones or the update to make changes to any modified existing DB entries.
All I know is the use of the _api_c2_
was the key to unlock something I’ve needed to help round out some ideas I’ve had for a few months now…basically much more use of JSON, javascript and eliminating unnecessary database writes. Appreciate you posting that.
I totally missed what @DjackLowCode s implantation I will add this to my methods.
Does it auto update, I would assume it does
Just make that arbitrary text be connected to a dynamic source for your original json and it should be fine in terms of auto update.
Yep. JSON to Bubble Type.
It’s already in her JSON Assistant plugin.
Ahh i meant linking a UID within the JSON to a Bubble ‘Thing’. Still amazed theres not a simple plugin that lets you set the data source to whatever text the UID is coming from, and can mark as a list, and then that element’s states refer to the Bubble Thing(s) those UIDs are connected to, without doing a search - it would instead appear as a Aggregate Search.
I assume you mean as an ‘individual data request’?
You can already use the Expression element for that (or a JStoBubble element).
They will both output a Thing (or things) based on their Unique ID, without doing a Search, but with an individual data request (or requests) instead.
Time for me to dig into Toolbox!
With the Expression element you can literally just enter the unique ID (in quotes), define the type, and it will output the thing via an individual data request.
For a list just make it an array of unique IDs.
Nice one, I didn’t know this…
Haha toolbox is probably the oldest and most powerful plugin ever made
Some progress, got it to work for single values.
For multiple values:
- Will need to split out multiple values before inserting the prefix.
- Need a separate toggle for each possible output value - I think it is kind of messy UI
Yet to test with all JSON derived types.
More later!
Yes it makes sense for Expression to have the conversion too. To be useful, would it add the prefix into a JS object, as per your example? And not into a JSON string, as the variable name originalJSON
incorrectly implies.
Going the other way, removing the prefix would be useful for Run Javascript parameters.
Then there is Server script. Server side structure of the API object is more complex.
We could extract the data component and remove the prefix, on the six “thing” inputs.
I’ll have to test to see if reconstructing the API object works from just the data component with the prefix and some template added.