Added better sorting to JSONEncoder.