I've not seen (yet?) JSON.stringify
to be non-deterministic in Node.JS.
There is no guarantee it to be deterministic on the specification level.
But what about V8; Is its implementation there deterministic? Is there a guarantee for it to remain deterministic for future V8 versions?
Edit:
With deterministic I mean that following assertion is true no matter what the value of json_str
is. (Given the value is a valid JSON string.)
const obj = JSON.parse(json_str);
assert(JSON.stringify(obj)===JSON.stringify(obj)); // always true
Edit 2:
Actually, I'm also interested for the following assertion to be true
if( deepEqual(obj1, obj2) ) {
assert(JSON.stringify(obj1)===JSON.stringify(obj2))
}
which is not the case (see answers).