Closed mage-ua closed 2 years ago
There's no order since JSON_Object
is based on StringMap
.
So I don't understand why in output keys appears out of order...
Expect:
kills,
deaths,
assists,
.
.
.
contribution_score
Result:
v5,
1kill_rounds,
.
.
.
kast
Hey there, As @MAGNAT2645 stated, this library is built on top of StringMap which is inherently unordered. This is not a technical problem because JSON objects don't need to be ordered for anything other than human readability, but I'd be happy to implement an optional "lock order of inserted keys" which tracks the keys in a separate array if you like. Will look into this over the next week. Cheers!
EDIT: Just an update here, I am still working on this - I've found some nice underlying quality of life changes that can be made in relation to this feature so there are quite a few changes in the works. Will keep you updated on the status.
Hey there, As @MAGNAT2645 stated, this library is built on top of StringMap which is inherently unordered. This is not a technical problem because JSON objects don't need to be ordered for anything other than human readability, but I'd be happy to implement an optional "lock order of inserted keys" which tracks the keys in a separate array if you like. Will look into this over the next week. Cheers!
EDIT: Just an update here, I am still working on this - I've found some nice underlying quality of life changes that can be made in relation to this feature so there are quite a few changes in the works. Will keep you updated on the status.
Hey @clugg I was wondering if you were still working on this? We are facing a bug when using get5 for our CS league where the captains are always random. Get5 will always pick the first item out of the players array as the captain who bans and picks for their team, but because the schema they expect is a Json object, the order is random and not what we specified. Your fix would allow us to fix this issue completely!
See https://github.com/splewis/get5/blob/master/configs/get5/example_match.json
I've just released v4.0.0. You can enable this functionality using obj.EnableOrderedKeys() or by passing JSON_DECODE_ORDERED_KEYS
as an option to json_decode
.
Thanks for your suggestion!
Hello! Thanks for the great library.
Is there any sort order?
This code gives a randomly sorted values on the second level object (paramsJson):
Output: