aeson-pretty icon indicating copy to clipboard operation
aeson-pretty copied to clipboard

Option to preserve key order relying on toEncoding

Open fizruk opened this issue 6 years ago • 6 comments

Right now the keys are always resorted when using encodePretty. However, sometimes it is desired to preserve the key order from toEncoding.

See https://github.com/GetShopTV/swagger2/issues/98 for a possible use case.

fizruk avatar Mar 16 '18 09:03 fizruk

This would definitely a plus. Right now there are many cases where we cannot use encodePretty (and use encode from Data.Aeson instead) because of this.

eltix avatar Sep 26 '19 14:09 eltix

I'm interested by this issue.

Unfortunately, toEncoding yields a Builder which does not contain any structure anymore, so it is not possible to format it again, except by converting it back to Value with decode, but the order will be lost.

guibou avatar Oct 30 '21 12:10 guibou

IMO this is a pretty serious issue that conflicts with this library's core mission:

The library provides a single function encodePretty. It is a drop-in replacement for aeson's encode function, producing JSON-ByteStrings for human readers.

martijnbastiaan avatar Nov 13 '21 09:11 martijnbastiaan

@informatikr @DougBurke Would you be open to a PR that fixes this behaviour?

theophile-scrive avatar Jul 01 '22 10:07 theophile-scrive

@theophile-scrive I've taken over maintainership for this package. I'd definitely be interested!

martijnbastiaan avatar Jul 01 '22 13:07 martijnbastiaan

@martijnbastiaan Very well. :)

theophile-scrive avatar Jul 01 '22 17:07 theophile-scrive