You should use a second format like this (from your example):
[ { "Key": 3, "Value": "AAA"}, { "Key": 8, "Value": "CCC"}, { "Key": 1, "Value": "ZZZ"}, ]
The reason is that JSON dictionaries do not even have a concept of sorting, itβs like asking a car to swim in water because it would be unnatural. You might think, βBut all I need to do is get them in the right order before sending them,β but the customer will not be able to see any order.
In the above example, the elements are placed in an array, not a dictionary, and the arrays are in order, because they are a list. You do not have to worry about the extra size, because it is actually very effective.
Another approach would be to expect the client to sort your data based on reading all Key fields, but this is not a very polite way to send ordered data at all.
source share