Note: This article originally appeared on tedparton.com on 03/10/2013
Recently I needed to return a JSON representation of a ColdFusion structure, but I needed one of the Key’s to be all lower case. I knew that CF natively uppercase’s Key names, but figured there had to be a way to change this.
It turns out that you can make the key value all lower case, or even mixed case, the trick is to enter it like a named array element. Here’s an example:
<!--- Create initial recordset ---> <cfset variables.structElementTest = structNew() /> <!--- Artist 1 ---> <cfset structElementTest.band1 = "MUSE" /> <cfset structElementTest["band1_website"] = "www.muse.mu" /> <!--- Artist 2 ---> <cfset structElementTest["band2"] = "Radiohead" /> <!--- Mixed case ---> <cfset structElementTest["BaNd2_website"] = "www.radoihead.com" /> <!--- Dump the results ---> <cfdump var="#variables.structElementTest#" label="Structure Element Test" expand="true">
Example Dump:
Heck, try it for yourself, I have whipped up a simple example page: Lowercase Structure Keys Example