Oh my god. It's full of code!

Posts tagged “serializeJson

Coldfusion serializeJson preserve case

Hey this is just a quick tip for any of you ColdFusion programmers who may be interacting with javascript while using JSON. ColdFusion being a non case sensative language has an annoying habit of changing the case of your structure key names when being fed through the serializeJson function, or most other functions that translate ColdFusion datastructures. The official statment is that you just need to change your javascript to expect all uppercase key names, but in some cases you cannot do that. There is a workaround however. Instead of declairing your structure keys like

<cfset myStruct = structnew()>
<cfset myStruct.keyName = "I won't preserve this key's case!">
<!---- this will be all uppercase. Sad face 😦 ----->


<cfset myStruct = structnew()>
<cfset myStruct['keyName'] = "I WILL preserve this key's case!">
<!---- this will preserve case. yay! ----->

so even after sending that structure through serializeJson the case of key name in the second example is preserved. Hope this helps someone, cause I know it was driving me crazy for a while!