dhall-haskell icon indicating copy to clipboard operation
dhall-haskell copied to clipboard

Preserve fields order in dhall-to-json

Open countoren opened this issue 3 years ago • 3 comments

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

countoren avatar Mar 06 '21 22:03 countoren

It appears that this is a limitation of using the aeson package for decoding JSON, at least for decoding arbitrary JSON Values. 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.

Gabriella439 avatar Mar 07 '21 05:03 Gabriella439

Oh, also, here is the relevant aeson issue discussing this limitation: https://github.com/haskell/aeson/issues/368

Gabriella439 avatar Mar 07 '21 05:03 Gabriella439

https://github.com/dhall-lang/dhall-haskell/issues/1813 is related.

sjakobi avatar Mar 08 '21 11:03 sjakobi