[Haskell-cafe] Ordered JSON objects?

Wojtek Narczyński wojtek at power.com.pl
Tue Dec 16 22:08:34 UTC 2014

On 16.12.2014 09:39, Tobias Dammers wrote:
> On Mon, Dec 15, 2014 at 11:01:12PM +0100, Wojtek Narczyński wrote:
>> On 15.12.2014 20:32, Tobias Dammers wrote:
>>> Anyway, one thing I'm running up against is that I am going to need
>>> ordered key/value collections, which I believe is something JSON does
>>> not support out-of-the-box: "objects" ({"foo":15, "bar":23}) are
>>> conceptually unordered key/value collections (and Aeson treats them as
>>> such, using hash maps as the intermediate storage format), so I lose
>>> ordering;
>> JSON does not forbid ordering of maps by key, I believe. But you'd need to
>> create an OrderedMap and patch aeson. It would be very useful, the mixing of
>> key order is nuisance for human JSON consumers.
> No, that's not what I meant. By "ordered", I meant that the in-memory
> representation of the document should maintain file order. Aeson uses a
> HashMap to store key/value objects, which is an unordered container;
> what you suggest would be something like Map (storing elements by key
> order), but what I'm talking about is more like [(Key, Value)], i.e.,
> keeping file order intact.
I meant a container maintaining order of additions. Indeed, it's not an 
OrderedMap, rather InOrderOfArrivalMap.

> I absolutely don't want to use "looks like JSON but isn't", I really want to stick with standard JSON,
> for so many reasons.

As long as the keys are unique, it is JSON, order of keys does not matter.

Caveat emptor.

More information about the Haskell-Cafe mailing list