-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
to_entries
always outputs keys sorted - can it be avoided?
#561
Comments
Do keep in mind that there's technically not an innate order for object keys. They happen to be (generally) stored in the order they are added, but that's an underlying implementation detail that really shouldn't be relied upon, as it could change without notice. That being said, to_entries does require some ordering to exist, even if it is arbitrary. The current implementation ends up calling As for whether or not it should sort them... I feel like they should be sorted. The implementation of object is doing some interesting hashtable things, though. It seems to be creating an indirection array to be used with hashing, to maintain insertion order and still allow @nicowilliams, thoughts? |
Yes - and generally I don't care much. While my human-parseable output generally is generated in the preferred order, or sortable by value,
Seems sorting keys when order is arbitrary is completely unecessary?? Why does
If it fixes my opinionated "problem", it would be very nice. It does seem others have stumbled upon it too, as per other issues. |
jq now actually keeps insertion order for objects internally, but it sorts keys in the Would this be a backwards-incompatible change? No, I don't think so. |
Although the |
Since |
@nicowilliams: excellent, thank you very much =) |
👍 |
I care about output ordering, as I intend to use automated jq output in a report. After using
to_entries
(orwith_entries
) my original ordering is lost.In these examples I want to keep the order
c, b, a
. The numeric values are an example; I can't use them for key ordering.Order changed by
to_entries
.Order changed by
with_entries
, because it usesto_entries
.Using
from_entries
is no problem. Usingreverse
as an example only.My problem is similar to the ordering issues in #48 "tsv and/or csv output support". I'm writing generic code though, and want to avoid manually specifying column ordering for each dataset.
Should
to_entries
produce key-sorted output?The text was updated successfully, but these errors were encountered: