Skip to content

Add support for ordered map representation of objects#12

Draft
farlepet wants to merge 1 commit intorhysd:masterfrom
farlepet:support-ordered-map
Draft

Add support for ordered map representation of objects#12
farlepet wants to merge 1 commit intorhysd:masterfrom
farlepet:support-ordered-map

Conversation

@farlepet
Copy link
Copy Markdown

This adds a new feature ordered-map that will use an IndexMap instead of HashMap in order to preserve the order of items in an object. This features is disabled by default.

This still needs work on the documentation side of things, and perhaps any minor cleanup. I just wanted to put it up as a draft to get some feedback on whether this would be accepted at all (I understand if the consensus is that this doesn't belong in this minimal library).

This adds a new feature `ordered-map` that will use an IndexMap instead
of HashMap in order to preserve the order of items in an object. This
features is disabled by default.
@cherio
Copy link
Copy Markdown

cherio commented Feb 11, 2025

An alternative to having IndexMap is to have an optional custom property in each Object (e.g. specified by the user) in the existing HashMap e.g. "_properties" which is a JSON array of object keys listed in order as they appear. This could be a compromise that 1) may not affect performance much, 2) achieve the goal of having an ordered list of object properties and 3) still maintain zero dependencies on other crates (speaking of keeping it tiny).

Looking at the code, this could be a minimally intrusive change in parse_object.

@farlepet
Copy link
Copy Markdown
Author

farlepet commented Mar 1, 2025

Yeah, back when I originally made this change, it was sort of a quick proof-of-concept to make the ordering more deterministic for a project I was working on. I no longer work at that company, so I no longer have any need for this personally (though if something like this was more widely desirable for this crate I still wouldn't mind helping out).

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