parse() Doesn't Preserve Property Name Ordering

Apr 26, 2014 at 2:52 PM
We'd prefer that web::json::value::parse() preserve the order of JSON property names within an object, instead of reordering property names alphabetically. Is alphabetizing the intended behavior? Round-tripping parse() to serialize() doesn't result in the original ordering. This is at least an issue for our debugging/sanity checks/visual confirmations. I believe parse had preserved order some releases ago(?).
Apr 26, 2014 at 3:24 PM
Hi BSalita,

You are correct that we used to preserve round-trip ordering for JSON property names. However, when you look at the actual JSON specification, you will find that "An object is an unordered set of name/value pairs." []
To improve performance when handling large objects, we switched to using a sorted container which allows faster lookups. At the moment, and for the foreseeable future, this will be alphabetic sorting.
This is at least an issue for our debugging/sanity checks/visual confirmations.
I can definitely understand that this makes it difficult to do a visual comparison of two large JSON objects. The best way to handle this circumstance would be to compare the JSON data structures in-memory (i.e. post-parsing) instead of trying to ensure that different serializers produce similar results. If you're looking to just test your application logic, this should be as simple as parsing the "target" JSON document and then performing a traversal.

On the other hand, if you're looking to test the Casablanca JSON implementation, I would recommend using another JSON library (several options are available on to parse the final documents and check if they are semantically equal.

Marked as answer by BSalita on 4/26/2014 at 10:23 AM
Apr 26, 2014 at 5:22 PM
Good info. Thanks.