JSON.parse() how to prevent alphabet sorting of keys

Viewed 20

I have JSON string that I retrieve from server:

"{ \"id\": 1, \"name\": \"Bill\", \"fields\": [\"a\", \"b\"] }"

When I do JSON.parse() then it sorts keys in alphabetical order:

{ fields: ["a", "b"], id: 1, name: "Bill" }

How can I prevent this sorting?

1 Answers

Official specification (json.org) states:

"An object is an unordered set of name/value pairs."

The order or properties should not matter, your application should have same results regardless. If you design your application around this order, it is a mistake.

Related