Parsing JSON Into zod schema using OPENAI GPT
I want to parse a JSON example https://store.steampowered.com/api/appdetails?appids=1702010
Into large advanced zod schema.
Do you guys have any experience doing this with gpt openai package??
Seems like pretty normal use case but I can't find any good examples
33 Replies
idk about AI but have you tried: https://transform.tools/json-to-zod
JSON to Zod Schema
An online playground to convert JSON to Zod Schema
I’m sorry but this is not even close.
I want any data => json formatted according to zod schema 😄
what do you mean
I want to parse any input into a JSON that has schema defined in zod.
wdym "any input into a JSON"
be specific here, give an example input
I guess you don’t understand how does gpt work, I want to put literally any string on earth and I want the gpt to output JSON from it. It’s pretty normal use case. For example v0.dev does it but without zod. Here is example input https://store.steampowered.com/api/appdetails?appids=1702010
I’m already doing it as well but the gpt is hallucinating a lot for me and Im looking for some good practices/tips/snippets
your example input is JSON bud
Sorry @iDarkLightning I think you are not helping here, you don’t understand my question. If you are curious about this topic feel free to DM me but let’s not spam this topic so others will be more willingly to give answers
Why are you using the raw API?
There's node packages that make this easier
I’m using OpenAI npm package but I have trouble incorporating the zod schema into it, even with the examples @Strike
npm
openai
The official TypeScript library for the OpenAI API. Latest version: 4.24.7, last published: 4 days ago. Start using openai in your project by running
npm i openai
. There are 1427 other projects in the npm registry using openai.@Jaaneek no like I mean accessing steam API
Or what exactly are you trying to do?
I'm a bit confused
give us an example of the JSON that the gpt would output if I gave it the string "I like web development"
1. I’m fetching the data from steam API
2. Im using this json from steam API as input to GPT
3. I Ask gpt to use data from steam API JSON and put it into JSON that is defined by my zod schema
….
I want it to be generic so I can also fetch the data from other places and always have it in my zod defined JSON format
I see but you don't only want it to work for the steam API?