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

https://issues.dlang.org/show_bug.cgi?id=4493

This was originally an issue with the unittests, but I thought it could become an enhancement request.

The only problem is the allocation. I don't suppose there's a way to lazily sort by the keys, is there?