According to MDN documentation for JSON.stringify:
Properties of non-array objects are not guaranteed to be stringified in any particular order. Do
I am pretty sure this is because of the way different JavaScript engines keep track of object properties internally. Take this for example:
var obj = {
"1" : "test",
"0" : "test 2"
};
for(var key in obj) {
console.log(key);
}
This will log 1, 0 in e.g. Firefox, but 0, 1 in V8 (Chrome and NodeJS). So if you need to be deterministic, you will probably have to iterate through each key store it in an array, sort the array and then stringify each property separately by looping through that array.