Open nazriel opened 6 years ago
Tbh. You should never rely on the order of entries in json; that's bad practice and will only lead to problems.
Maybe you are right. Maybe you are not.
The fact is: 1) I have such need despite whenever it is good practice or not. JavaScript's stringify preserves order for some reason. And that reason was used to "normalize" behaviour in the application I am working with in order to make this data output independent of the language that is used. 2) vibe.d currently is inconsistent. One way preserves the order. Another doesn't. So either inconsistency should be removed or optional parametrization should be available.
IMHO current "random" behaviour is only due to fact that D's AA are used as "output type" for JSON objects and this doesn't preserve the "insertion" order.
m_object[key].m_type = Type.undefined; // DMDBUG: AAs are teh $H1T!!!11
;)
I am not sure which way is the way to go - but I would like to know the opinion of original authors like @s-ludwig .
I can only imagine it will drag performance down using a sorted collection, instead of AA's.
An alternative implementation would probably be better than modifying the existing Json implementation.
I am currently working with project that has .json files under version control. The previous version of application written in NodeJS was using stringify to make sure that order of keys in json objects was sorted in a given way.
I am able to reproduce this behaviour when using serialization on data structures. OK Example:
NOT OK example:
Is there any way to make NOT OK example, the OK one? ;)