Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: