Filter output from chatgpt to only JSON

I’ve been working on this for a while, but I can’t get it to work. I have a flow where I scrape a website. This data goes through ChatGPT, which formats it into JSON for me. In the prompt, I explicitly tell it to output only JSON—I have a very detailed prompt about this—but sometimes ChatGPT still adds something before it, like:

“Here is your JSON format:”

I think the only way to fix this is by creating a filter that removes everything before and after the JSON. I created a regex, and when I validate it in a JSON checker, it correctly selects only the JSON. However, I don’t know how to apply this in Make.com.

Who can help me with this? Should I use a filter or a text parser, and which one?

Hey Jos,

you can use a Match Pattern module to get only the JSON from the output. ChatGPT is ultimately a text generator that, no matter what you tell it, will always try to generate text.

1 Like

You can also trick ChatGPT into doing your bidding by telling it things like you will get fiered if there is anything other than JSON in the output, or that you will lose your biggest client, or your company might get sued. It’s been know to help ChatGPT stay on the right track.

L

1 Like

Thanks, this worked for me!

1 Like

Which one? You should mark it as a solution in case someone else has the same problem.

L