3 ms·
> Javascript environments ... guarantee that they'll preserve object key order when JSON is evaluated Yes, but only for non-integer keys.
by ash 3y ago
> Javascript environments ... guarantee that they'll preserve object key order when JSON is evaluated
Yes, but only for non-integer keys.
- gmfawcett 3y agoIs there such a thing as a non-string JSON key to be evaluated? https://www.json.org/ https://www.json.org/ suggests not.
- ash 3y agoYes, in the context of JSON handling by JavaScript. I meant string keys that can be interpreted as non-negative numbers. Those are traversed first, the rest of the keys are coming in insertion order. For example: > JSON.stringify({'one': 1, '3': 3, 'two': 2, '2': 2, 'three': 3, '1': 1}) '{"1":1,"2":2,"3":3,"one":1,"two":2,"three":3}'
- gmfawcett 3y agoThanks for explaining. That behaviour is... interesting!