Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is JSON serialization deterministic?

Tags:

json

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.

like image 669
Jason S Avatar asked Mar 31 '26 07:03

Jason S


1 Answers

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.

like image 129
Khoyo Avatar answered Apr 02 '26 19:04

Khoyo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!