D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4493 - Add sorting capability to toJSON
Summary: Add sorting capability to toJSON
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: Andrej Mitrovic
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2010-07-22 13:43 UTC by Mario Kroeplin
Modified: 2014-09-09 09:23 UTC (History)
3 users (show)

See Also:


Attachments
replacement for unittest of std.json (2.16 KB, application/octet-stream)
2010-07-22 13:43 UTC, Mario Kroeplin
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Mario Kroeplin 2010-07-22 13:43:13 UTC
Created attachment 694 [details]
replacement for unittest of std.json

The only non-trivial unittest is commented out as "currently broken".
This is confusing: in fact, not the implementation but only the unittest is
broken.
The reason is, that the order of the name/value pairs in a JSON object is
unspecified:
the serialization uses foreach(name, member; value.object)!

The example just before the "currently broken" one is {"a":1,"b":null}:
as the result could also be {"b":null,"a":1}, this test is broken in theory,
but not (yet) in practice.

Please, consider to replace the broken unittest with the attached proposal.
Comment 1 Mario Kroeplin 2010-07-26 12:15:41 UTC
    assert(find(json, result) != null, text(result, " should be in ", json));
should have been
    assert(!find(json, result).empty, text(result, " should be in ", json));
Comment 3 github-bugzilla 2014-09-09 09:23:13 UTC
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/374b6e03e724fe3da02093aa0665112135df861c
Fix Issue 4493 - Add sorting capability to toJSON and add another unittest.

https://github.com/D-Programming-Language/phobos/commit/8b851030f2bd32098e5ae4654e6c2b5082ccee79
Merge pull request #2120 from AndrejMitrovic/Fix4493

Issue 4493 - Add sorting capability to toJSON and add another unittest