Tips to keep OpenAI JSON clean for FAQ/Software schema?

Hi everyone! I’m using the OpenAI API to generate two things for my WordPress site:

  • FAQ schema from my page Q&As

  • Software Application schema for my APK pages

It works, but sometimes the JSON comes back with extra fields or tiny format errors.
What’s the easiest way you use to keep JSON strict and valid every time?It works, but sometimes the JSON comes back with extra fields or tiny format errors.
What’s the easiest way you use to keep JSON strict and valid every time?

This is the website, please advise

Thanks!

Welcome to the developer community @ebeth2649

I’d recommend using structured outputs.

You could create a jsonSchema definition to validate the returned JSON against. To create a schema definition (if there isn’t one already available), you can pass a valid JSON (with all fields needed and no extra fields) to an LLM model and tell it to create the schema.