D
D
Daniil Sugonyaev2018-10-09 23:47:45
JavaScript
Daniil Sugonyaev, 2018-10-09 23:47:45

Do keys preserve order in a JSON object?

The point is this. At work, I'm editing a product catalog. A lot of properties are passed from the back. I need to access individual keys and use them in different places on the page. The data format is:

props: {
"action": true,
"brand": "prada",
...
}

And most of these properties are listed as a product characteristic. To do this, another array is passed, essentially a duplicate object, which is already sorted as needed:
propList: [
{name: "Бренд", value: "prada"},
...
]

I would like to reduce the amount of information transferred in this way:
propList: {
brand: {name: "Бренд", value: "prada"},
...
}

However, it must preserve the sort that the backing passes. The question is. Whether JSON preserves the sorting of strings specified on the back. Opinions differed in the team, some say that this is not clearly stated in the specification and the situation may be different in different browsers. Opinions also differ on the forums. Have you experienced this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2018-10-09
@coolswood

The order of keys in a JS object is not guaranteed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question