DEV Community

Cover image for How to Ask AI to return JSON in the Right Way

How to Ask AI to return JSON in the Right Way

Igor Boky on July 06, 2023

Quite often when you request AI to send you a JSON, it responds with anything but not the JSON, or JSON is just a part of it. There are some way...
Collapse
 
n_demia profile image
Natalia Demianenko

Useful tips, thanks Igor 🚀
I also use approach with providing JSON schema in prompt e.g.

Generate object describing {{item}} using the following JSON schema {{schema}}
Enter fullscreen mode Exit fullscreen mode

so we can define properties types and required properties. I hanen't got random responses with such prompts but maybe I was lucky😊

Collapse
 
johnrushx profile image
John Rush

I actuallly prefer YAML.
Much shorter and stable