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

When I define data roles for a thing, this plugin seems to stop working properly.

For example, I have a thing called “shirts” a string field “brand”, and the default fields "_id and _type.

When I run the plugin without any data roles, I get a json with all the fields I expect to see

[
  {
    "brand" : "Fruit of the Loom",
    "Created By": "1579901485399x251684328699599330",
    "Created Date": "2020-02-26T19:58:26.262Z",
    "Modified Date": "2020-02-26T19:58:26.518Z",
    "_id": "1582740420372x895383113522217000",
    "_type": "custom.shirt"
  }
]

When I run it with data roles, even if I have the permission to see all of the data, I get an incomplete set of fields:

[
  {
    "_id": "1582740420372x895383113522217000",
    "_type": "custom.shirt"
  }
]

It seems like that this plug in searches for things not as the logged in human user, but as a different entity. If that’s the case, how can I define a data role for this plugin? If that’s not the case, how can I workaround this?

Does this happen with other server-side JSON plugins?
JSONator utilizes two bubble-supplied server functions to get the raw JSON from the DB. Based on what you’re showing me, I’d wager that these built-in functions (which are created and administered by bubble) aren’t retrieving your data. This is likely a configuration issue or a limitation of those function’s ability to retrieve db JSON with when data-roles are applied.

Is there an API or Server date-role? I don’t believe there is?

You can do a little searching on the forums for these functions which retrieve JSON:
getObjectFromId()
getObjectsFromIds()

You can try another JSON plugin to test or try using the toolbox plugin to see of these functions are working as expected for you. If they are working, I can see if it is indeed related to JSONator, but again, from what I’m seeing in your post it seems unlikely.

If it is an issue with the function then this seems like a conversation with bubble on how to address this.

Hello Jon2

Your plugin seems very promising. I need this to quickly build a new app using bubble’s API but I want to limit the numbers of API calls by using nested data. So great!

I must be doing something wrong however.

My DB structure is a simple User > Company
I just dropped the WF action in a new backend WF endpoint and did a Search for Users with a simple sort and didn’t add any config.

That’s all I would need to do to get some results, no?
When I call my new endpoint in postman, I get an empty
{
“status”: “success”,
“response”: {}
}

Am I missing something?

remove privacy settings and try

Thank you @Bubbleboy
Privacy settings are OK. I am using the obj/user endpoint without any issue.
I did just tried with checking the “Ignore privacy rule” on the endpoint and I still get an empty result.

I would actually remove your Privacy settings and then test…thats what i meant to say…maybe its just me but when i have Privacy settings…its will not generate the JOSN.

Has anyone had any luck using this plugin whilst using privacy settings? My normal settings are to only access an item if the creator is that item’s creator.

Will this plugin only work with no privacy settings for the Types being turned into JSON?

This plugin works great, but I am running into an issue! When a number field is 0, that field does not generate, but I need it to generate. So is there a way to get around this? Any help would be appreciated!

1 Like

Unfortunately, I’m not aware of any way to sidestep privacy settings for server-side workflow scripts. If someone could educate me on a solution to this it would be appreciated. One work around for this might be to create a field called unlocked and configure your privacy settings to allow full access when the field is not empty. Then you can fill the field just in a step just prior to reading with JSONest and delete the field data just after. Its not a ‘best practice’ and, of course, it doesn’t take into account any nested things, but its an option. Otherwise, the only other solution would be constructing your app to enforce its own data privacy rules vs relying on bubble to do this. I may be way off base here so anyone feel free to jump in an correct me.

This plugin is a lifesaver. However, one issue I have is that when I retrieve a list of Things, the Creator (built in field) of the thing is only output in the JSON as a string of their bubble ID, not the nested user object containing their name, image, etc. Is that a limitation or am I missing something?

The second question I have is if there is any way to manipulate the data within the JSON? For example, I am sending the JSON through to the SendGrid API, but before I do, I would like to truncate the length of a “Description” field(string). Is this possible with jsoNest or do I have to use something else to manipulate the JSON?

Any help would be appreciated.

Thanks,
Paul

Hi there,
How could I retrieve an attribute value of an option set using JsoNest?
I can get the display part, but I didn’t find a way to go further and expand the option set. :-\

Any idea? @jon2?

Thanks in advance for your help.


Thierry

Option sets didn’t exist when this plugin was created, and unfortunately I don’t know about how to look those up. To ‘expand’ a UID (and get the nested JSON data) the JSONest plugin code uses a bubble-specific server-side javascript method called getObjectById(). This method retrieves the data inside a thing using its 32 digit ID. It is that function which is at the heart of JSONest and only works for db things. I’m not aware of similar such method that lets you retrieve an option set. It would be nice.

I learned about getObjectById() from the toolbox plugin support thread on this forum. Its not documented anywhere else besides the toolbox plugin. Perhaps @mishav has some special insight into another undocumented method that can retrieve option sets?

Thanks @jon2 for your reply.
I’ll check the thread you mentioned, and hope @mishav or someone else could help.

I’m attempting to use this plugin but when I try to generate the JSON with a list of things, it throws an error "problem loading UIds of the thing(s). Any thoughts as to why?

Sounds like it could be empty data. Have you tried step-by-step in the debugger or logging your thing’s UIDs to the screen,etc to verify you’ve actually got data going into JSONest?

Trying to wrestle around with the date format. Is it possible to use mmmyyyy format, or only the three or so formats in the example?

Also, is it possible to replace/update contets of the JSON. For example, I have an “end_date” field, which I want to set to “Present” in my JSON string if there is no date there. This is fairly simple with something like JSONata, but I can’t figure out if you can do expressions in here… e.g.

'end_date' : ($exists(end_date) ? end_date : 'Present')

JSONest doesn’t use any external libraries generate date formats, its sort of a basic thrown-together solution built for speed. I don’t see too many formatting options to the output fields on the roadmap. Mainly because of the following reasons.

(a) there are limitless numbers of ways people may want to format a field. In short, it is hard to build a lean and suitable tool for all requirements.
(b) speed–especially when processing many records. Bubble has a 10s limit on run-time and simplicity in processing data after it has been retreived helps with that.
(c) a lot of things can be worked around with find-replace to the resultant JSON text
(d) special fields can be used to format data in bubble prior to exporting with JSONest.

I’d take a look at C & D. Particularly D.

Create a text field in your thing to store your date in there the way you want as text. This isn’t always workable depending on where and how often that date gets updated or how many records you have with the date. However, if it IS workable you could use bubble’s date formatting and a conditional

when thing's date is empty:formatted as text

yes: Present
no: thing's date formatted as mmmyyyy

Thanks @jon2

I figure I can pull the output into another JSON transformation tool like JSONata or similar (which I haven’t been able to successfully use to pull nested data :roll_eyes:).

It’s not the worst thing trying to cludge together separate plugins to achieve a single result - and it’s innumerably easier in Bubble than in other tools like Drupal or Wordpress!

if you have some JS knowledge, the toolbox plugin server-side script action will let you work on data and pipe the result into subsequent workflow steps. This can also be a reasonable solution too. Good luck

Thanks!

My JS knowledge is limited, but I manage! :sweat_smile: