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

Does the JSON spec actually say that those objects should be "equal", or does it just leave that detail to implementations?

In JavaScript at least, those two are not exactly "the same", in the sense that you can observe the difference if you want to. If you parse those JSON strings and then iterate the keys (e.g. with Object.keys), the ordering will be different.



The JSON spec only defines the JSON text format. It doesn't say what the text means. There are obvious interpretations, but every program that reads or writes JSON can decide what it does with it.

On the other hand, the thing that makes JSON actually useful is the interoperability, that JSON written by one program, on one platform, can be read by another preterm on another platform. Those programs have to agree on a protocol, what the JSON text must satisfy and what it means. It's usually not considered valuable to require object properties to be in a specific order, so they don't. But they could.




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

Search: