Validate json in backend workflows

I am struggling with backend workflows as I need to process some JSON with the JSON parser plugin. The problem is that some of the JSON objects, which are returned by OpenAI, are not valid. I need to validate the JSON before parsing them. If the JSON is not valid, I will skip the JSON parser steps. Otherwise, the JSON parser fails, and because there is no exception handling in backend workflows, the entire workflow fails silently.

I’ve looked for some APIs online to validate JSON, but I couldn’t find a suitable one since this task is usually performed on the client side, with code.

Is there any way to write code or use a different method on the Bubble backend to validate JSON and then perform a specific action (like updating a thing) depending on whether the JSON is valid or not?

Hello @alejandro2

OpenAI released Function calling recently where you can directly get JSON object as output without us having to ask the model to explicitly do it in the prompt . This helps to easily consume OpenAI API with confidence that you will get the expected JSONresult only.

hi @cmarchan Thank you for the quick reply. However, the function calling method has its issues and doesn’t suit my purpose. It doesn’t necessarily return all the parameters you request in the function, even if you set them as required. In my case, I won’t know in advance what the schema of the returned JSON will be.

I’ve installed a JavaScript plugin and am currently trying to use it to determine if the JSON is valid.

@alejandro2

I see. Another idea could be to build a self-calling endpoint that returns your JSON string from OpenAI into a JSON object. Send your JSON as a POST with a one string parameter (text), use the backend action “return data from api” (set it to other content type application/json). This way you will attain two things, (1) Get yourJSON converted to Bubble fields and (2j An automatic error checker if it fails where the likely cause was due to the buggy JSON.

Hope the above makes sense :smiley:

hey @cmarchan that is a great idea, thanks for suggesting it. I will try it out and keep you posted.

1 Like

hi @cmarchan I finally solved this topic using the javascript workflows plugin. This way, it is possible to write some code which will validate a json and return true or false depending on whether it is valid or not. thanks a lot for the idea nonetheless.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.