Canonicalized then prettified JSON
Canonicalization normalizes the type serialization and sorts the fields.
Prettifying adds back white space and line separators.
We need to come up with a standard for prettify.
I would like to see a YAML equivalent of this diffability. Maybe that is as simple as just converting from YAML to JSONC then converting the canonicalized JSONC back to YAML. The JSONC to YAML conversion process will also need to be standardized. A JSONC canonicalizer might not exist yet. Definitely not this simple.
Note: Prettifying makes it no longer canonical, but is necessary for diffability.
The RFC offers a sample ES6 JSON canonicalizer.
The following Open Source implementations have been verified to be compatible with JCS:
— Open Source Implementations
Canonicalize
Raw
{
"numbers": [333333333.33333329, 1E30, 4.50,
2e-3, 0.000000000000000000000000001],
"string": "\u20ac$\u000F\u000aA'\u0042\u0022\u005c\\\"\/",
"literals": [null, true, false]
}
Remove whitespace and normalize serialization
{"numbers":[333333333.3333333,1e+30,4.5,0.002,1e-27],"string":"EURO$\u000f\nA'B\"\\\\\"/","literals":[null,true,false]}
Sort
{"literals":[null,true,false],"numbers":[333333333.3333333,1e+30,4.5,0.002,1e-27],"string":"EURO$\u000f\nA'B\"\\\\\"/"}
Prettify
{
"literals": [
null,
true,
false
],
"numbers": [
333333333.3333333,
1e+30,
4.5,
0.002,
1e-27
],
"string": "EURO$\u000f\nA'B\"\\\\\"/"
}