On 09/05/2014 01:23 AM, David Hall wrote:
> It does appear without creating my own function i will be unable to
> iterate through the object in sequential order.
Perhaps not. Have a look at do_dump() in dump.c. The interesting part
starts with the line:
if(flags & JSON_SORT_KEYS || flags & JSON_PRESERVE_ORDER)
Basically you get a list of the keys together with their serial numbers
(the serial numbers tell you the order in which the keys were added),
sort it by serial number, and then iterate using that list of keys.
> I am curious to know how the Jansson decides on the order of which to
> store its keys?
The library uses a hashtable implementation, so it is optimized for fast
key access rather than iteration. In addition, the hash function is
randomized to avoid hash collision attacks.
The people who designed the protocol you are using did not do you any
favors. The Jansson library is not alone in implementing object
iteration the way it does. For example the ECMAScript spec allows
implementation-defined iteration order in for .. in loops.
If they wanted to put things in order, they should have used an array!
JKL