I am working with an applcation that serializes JSON in a way I did not expect. Is JSON serialization deterministic? In a Chrome console, I see
> JSON.stringify(3)
"3"
but this application serializes the number 3 to "3.0".
Both are clearly legal according to the JSON spec(s) ECMA-404 and RFC 8259, as is the serialization "30.0E-01".
Is there anything in the JSON standard that specifies what "canonical" serialization is supposed to produce? I couldn't find anything.
Well, one specific serializer might produce deterministic output. But there is no standard canonical format (at least widely used, there is this Internet Draft - but it never became an RFC, and is far from it).
Even if there was a "standard" somewhere, it is not in widespread usage, and so you cannot expect JSON documents to uphold it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With