Format JSON object to save in WeWeb variable

Hi, this issue was solved during the office hours on 30 April 2024. I was instructed to post here with the issue and how it was solved.

Problem Introduction
Working with openai chat completion extension(official weweb one), and json mode with openai. The problem faced was that the json returned in the reply by openai wasn’t formatted properly as json.

Solution
Using just few words of code. We could parse the Not JSON into JSON.
The answer was given by one of the community members on the call. And it was using the JSON.parse method on the object that was being returned from openai.

Suggestion by Joyce was that json.parse wasn’t available under the formulas.

Please let me know if any other additional information was needed.

Hi @red812 :wave:

Thanks so much for sharing this here :smile: My suggestion to post on here was before Rian found the solution for us but it’s still cool to have the community topic.

For readers on here, the idea is that if you’re receiving a JSON object from an external API and want to store it in a variable in WeWeb, you can do this by adding a little bit of JS. For example:

JSON.parse(yourVariable)

We created a product ticket to add a no-code formula so you don’t need the JS in the future :slight_smile:

I couldn’t find a way to DM you on here, or DM doc, so I thought a post would be the best way.