dhall-haskell
dhall-haskell copied to clipboard
Preserve fields order in dhall-to-json
It could be helpful to have dhall-to-json
to maintain the field order of a Json object in dhall record sets(or some other alternative type) instead of having it order alphabetically.
some application might be effected by the fields order of a Json for example. Or some user will order the field in a specific way in order for them to have the Json more readable (sub objects fields usually are pushed to the end).
this ticket is base on this topic in dhall discourse
It appears that this is a limitation of using the aeson
package for decoding JSON, at least for decoding arbitrary JSON Value
s. The reason why is that the Value
type used to represent schema-free JSON uses a HashMap
to represent JSON objects and that representation does not preserve the key order.
So it looks like this might not be fixable without switching to another underlying package for working with JSON values.
Oh, also, here is the relevant aeson
issue discussing this limitation: https://github.com/haskell/aeson/issues/368
https://github.com/dhall-lang/dhall-haskell/issues/1813 is related.