logoalt Hacker News

ponty_rick10/01/20242 repliesview on HN

> 11:43 Fields are generated in the same order that you defined them in the schema, even though JSON is supposed to ignore key order. This ensures you can implement things like chain-of-thought by adding those keys in the correct order in your schema design.

Why not use an array of key value pairs if you want to maintain ordering without breaking traditional JSON rules?

[ {key1:value1}, {key2:value2} ]


Replies

benatkin10/01/2024

> even though JSON is supposed to ignore key order

Most tools preserve the order. I consider it to be an unofficial feature of JSON at this point. A lot of people think of it as a soft guarantee, but it’s a hard guarantee in all the recent JavaScript and python versions. There are some common places where it’s lost, like JSONB in Postgres, but it’s good to be aware that this unofficial feature is commonly being used.

YetAnotherNick10/01/2024

I don't think openai models supports this pattern. You can only have array of fixed types. Or basically keys should be same. See [1]

[1]: https://platform.openai.com/docs/guides/structured-outputs/s...