-
Notifications
You must be signed in to change notification settings - Fork 440
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
Return the keys of dictionaries in order #407
Comments
I think this goes against the spirit of JSON quite a lot. Having an ordered dict type would be a fairly minor improvement in expressiveness compared to forcing people to use lists of pairs (or lists of singleton objects).
|
Could this be reconsidered? I've got a large collection of CloudFormation templates to work with, and a lot of different people working on them. CloudFormation's preferred formatting is a "logical" order, which is not alphanumeric. It would make transitioning to Jsonnet easier if I could preserve the general ordering of the keys so that the resulting artifacts can be read the same way as their not-yet-converted counterparts. As it is, changesets are tricky to review and the resulting artifact has an unexpected format, making it more difficult to read. |
Hmmm... One way to handle this use case that would be to add a hidden So for example:
could produce the following json:
EDIT: of course you wouldn't add field_order manually, but use some kind of adapter/wrapper. |
I was thinking about a different thing, was a while since I checked on this ticket. Still, this solution solves at least some problems with ordering.
It works nice in case when I use jsonnet to monkeypatch a bunch of objects but not as good if I need to add new objects to the map. |
Using jsonnet with k8s I've noticed an interesting pattern—whenever you specify a list of key-value strings in k8s, jsonnet's objects work better. One way to use that is to map command line aruments, e.g.
becomes
--tls-cert=/abc --tls-key=/def
One problem with that approach is that jsonnet sorts all the keys, thus making it very hard to deal with situations when key order is important.
I'd like to see a mechanism to turn objects into what's basically an OrderedDict of python.
The text was updated successfully, but these errors were encountered: