Struct Ordering

I’ve been building a very large struct for passing information to a client’s API.  This thing has objects nested in objects 3 levels deep in some places.  I find it’s easiest to work with a struct visually as I’m building these things, then use the “serializeJSON()” function to turn the whole thing into a JSON string.

First, to preserve casing, each item in the struct needs to be declared this way:  MyStruct[“MyItem”] instead of MyStruct.MyItem.

The issue I was running into though is ColdFusion doesn’t preserve the order in which items are added to the struct.  Instead it sorts things alphabetically.  Fortunately, ColdFusion 2016 introduced the ability to keep the order as they are added by declaring a new struct as:  structNew(“ordered”).  This is going to be a lifesaver on this project!