Skip to content

Order object properties by original name or keep order as set in JSON schema - #1090

Open
mhatzl wants to merge 4 commits into
oxidecomputer:mainfrom
ferrous-systems:mh/preserve-order
Open

mhatzl wants to merge 4 commits into
oxidecomputer:mainfrom
ferrous-systems:mh/preserve-order

Conversation

@mhatzl

@mhatzl mhatzl commented Oct 8, 2026

Copy link
Copy Markdown

This PR adapts the property sorting for structs from the sanitized names to the original ones set in the schema. e.g. common properties such as $schema are now sorted starting with $ instead of s.
With this ordering, serializing will create JSON content with correctly sorted properties (excluding generic maps).
Downside is that properties of Rust structs may not be alphabetically ordered.

Added the feature preserve_order, to keep the property order as set in the JSON schema.
This requires that deserialization is done in a way that preserves ordering, which serde_json does with the same preserve_order feature flag.

@ahl

ahl commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

I have not yet looked at the code, but do you think this is best as a crate feature or as a runtime setting? I could see the latter potentially making sense given that there are other flags that affect code generation.

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