Comment by hnlmorg
3 months ago
The JSON specification describes objects as unordered. Which means any standards compliant JSON encoders or decoders can and will produce maps in different orders even when the same object is passed through twice.
It’s also worth noting that quite a few languages don’t guarantee ordered maps either.
If you want an ordered map then you really need a key/value map inside an array:
[
{
Key: “:thumb:”,
Value: 4
},
{
Key: “:smile:”,
Value: 1
}
]
Though in this specific instance, you’d be better off with more specific key names like “emoji” and “count” (respectively).
Edit: HN stripped the emojis from my comment so I added ASCII placeholder strings into the example to illustrate the same point.
No comments yet
Contribute on Hacker News ↗