Skip to content

Conversation

@mattt
Copy link
Owner

@mattt mattt commented May 28, 2025

According to the JSON spec (emphasis added).

6. Objects

[...] The JSON syntax does not impose any restrictions on
the strings used as names, does not require that name strings be unique, and does not assign any significance to the ordering of name/value pairs. [...]

And yet... humans sure seem to ascribe a lot significance to the order of properties in a JSON schema.

Say you're auto-generating form UI for a createEvent tool that takes a start and end. If you use lexicographic ordering, you'll be asking users to start with the end in mind.

Balderdash!, I say.

This PR updates .object to store properties as an OrderedDictionary<String, JSONSchema>. Yes, this adds a new external dependency on swift-collections, but I don't think that's too onerous. The juice seems worth the squeeze, IMO.

@mattt
Copy link
Owner Author

mattt commented May 28, 2025

(BTW, the actual change to the implementation is minimal. Most of that 1k diff is from 120d385, which just wraps the existing tests in a test suite)

@mattt mattt merged commit 277b300 into main May 28, 2025
1 check passed
@mattt mattt deleted the mattt/order-preserving-initialization branch May 28, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants