Skip to main content
Inspiring
November 7, 2012
Question

Why do Coldfusion structure key cases change depending on declaration style?

  • November 7, 2012
  • 1 reply
  • 4026 views
In this simple component (test.cfc):

component {

     VARIABLES.obj = {};

     VARIABLES.obj.foo = "bar";

     VARIABLES.obj['foo2'] = "bart";

    remote function func1() {

        return VARIABLES.obj;

    }

}

The response from the URL “/test.cfc?method=func1&returnformat=json” looks like this:

{
  • foo2: "bart",

  • FOO: "bar"

}

Note that if you declare the property of a structure with dot notation, it is returned in uppercase. Using array like declarations returns it as you specified.

This is still apparent when dumping a structure in a page, but is more of a problem when accessing the results via JSON in a Javascript appliation, as this is case sensitive.

Pete

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
November 7, 2012

Why do Coldfusion structure key cases change depending on declaration style?

I think it is just a quirk of ColdFusion.

Inspiring
November 7, 2012

Being OCD-ish and a Data Nazi, it kind of gets me too, but it's nice to know CF sees those keys as case insensitive, and really the only time you see the bad casing is when you dump the structure.

Still, I am pushing for properly cased structure keys for COLDFUSION 11!!!

I think someone said if you use structInsert( structName, keyName, value, true), it will maintain the casing.

Inspiring
November 7, 2012

That makes sense, using structInsert specifies a string for the key, in the same way "VARIABLES.obj['foo2'] = "bart";" does.

But surely it'd still make more sense if dot notation created lower case key names?

Is there some underlying Java reason behind it?