I’m very new to serialization and I’m having a problem. I’m using javascript and JSON to serialize a key column consisting of floats, strings, and arrays of floats or strings. I have one rule. For the purpose of comparison, arrays are bigger than strings and strings are bigger than floats. Strings are compared alphabetically and floats are compared numerically.
So before serializing, I sort the key column but when JSON serializes the key column the order is gone.
For Example if I start with the following key column:
11,
2,
"1"
after sorting I’ll get:
"1",
2,
11
but after serializing, I’ll get:
"11",
"2" ,
""1""
Does anyone know how I can save the order? Is there any other serialization method that could preserve this order? any suggestion is highly appreciated. Thank you so much.
If I recall correctly, JSON may rearrange key ordering. Different browsers will arrange object keys differently. ONLY way to preserve order is by using array or [].