A dev on my team just asked me if there is a way to have CB send back a JSON conversion in alphabetical order. This is really just a cosmetic thing as it make it easier to debug and the API spec lists all of the returned elements in alphabetical order. It seems like CF and the CB JSON serializers both send back JSON in no particular order despite the order of the object prior to serialization. Is there any way to control this?
I'm guessing the object in question is a struct? Because I'm pretty sure arrays would be serialized in order. Structs are inherently unordered so it's not CB or CF's serialization that's shuffling things around, it's probably the object itself having no order.
In Railo you can create a linked struct where the keys stay in the defined order. I believe structnew('linked'). I'm not sure if CF or the particular version of CF you are working in supports this. If not, you would probably have to manually serialize your object using structsort() and looping over the keylist.
Yes, the object is a struct, and I'm using CF9. I'll lookup what you suggested and see if there is anything that can be applied in CF9.