Replies: 4 comments 4 replies
-
Likewise YAML is ordered alphabetically when using Python's PyYAML has |
Beta Was this translation helpful? Give feedback.
-
This behaviour is currently expected due to the way that maps work in Go - the order is internally randomized when it's parsed with To dive into the details why this happens - JSON and YAML are internally unmarshalled into a I suppose this all begs the question: why would you need to parse JSON/YAML only to re-render it directly? And, why does preserving order matter? |
Beta Was this translation helpful? Give feedback.
-
I agree it's a niche use case. Here's mine.
This works well, and involves parsing JSON/YAML only to immediately re-render it.
Yes, technically it doesn't, but it makes things more readable. For example,
is more readable than the alphabetically ordered version
Currently I've worked around that by doing
|
Beta Was this translation helpful? Give feedback.
-
another reason to keep order for us is if we rebuild a json file using gomplate then you could have false positives for git changes and have lines added and deleted due to the order change, whereas the file content as a whole has not changed. |
Beta Was this translation helpful? Give feedback.
-
I have following template:
then I call
gomplate -f input.tmpl -o output.tmpl
the output is:
what I want is:
Is there any way to preserve ordering when outputing json?
Beta Was this translation helpful? Give feedback.
All reactions