[Haskell-cafe] Ordered JSON objects?

Tobias Dammers tdammers at gmail.com
Mon Dec 15 19:32:20 UTC 2014

I'm building a "thing" that is supposed to use JSON 'documents' as its
building blocks, providing various (pluggable) storage backends and
presentation frontends. Non-techie/semi-techie (frontend dev, web dev,
etc.) compatibility is needed, which is why I want to keep the data
model "simple" and dynamically typed.

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; OTOH, flat lists ([15, 23]) do not have keys, and lists of
"pairs" (two-element lists) produce uglier syntax ([["foo",15],
["bar",23]]), but they are the "correct" solution.

Ideally, someone is going to step up and tell me that both I and Aeson
have misunderstood JSON, and objects are really supposed to be ordered
after all, in which case I'd need an alternative to Aeson (or someone
needs to patch it?). Or I could bite the bullet and go with [["foo",15],
["bar",23]]. Or I could ditch JSON as the canonical format and go with
something custom, or, shudder, XML.

Thoughts? Hints? Ideas?

- Tobias (tdammers on freenode)

More information about the Haskell-Cafe mailing list