SerializeJSON variable name capitalization

836 views
Skip to first unread message

Serge Droganov

unread,
Jul 29, 2011, 4:09:30 PM7/29/11
to Railo
Hello,
Why does Railo capitalize variable names in SerializeJSON output?
Is there an option to preserve original case?

This is a nasty problem since all thirdparty javascripts use lowercase
variable names, and it is sucks a lot to rewrite thirdparty sources
each time.

Thank you,
Serge

Peter Boughton

unread,
Jul 29, 2011, 4:15:22 PM7/29/11
to ra...@googlegroups.com
ACF compatibility.


From docs for serializeJson:
> Note: ColdFusion internally represents structure key names using
> all-uppercase characters, and, therefore, serializes the key names to
> all-uppercase JSON representations. Any JavaScript that handles JSON
> representations of ColdFusion structures must use all-uppercase
> structure key names, such as CITY or STATE. You also use the
> all-uppercase names COLUMNS and DATA as the keys for the two arrays
> that represent ColdFusion queries in JSON format.

Serge Droganov

unread,
Jul 29, 2011, 4:20:42 PM7/29/11
to Railo
Does Adobe have a real reason for this?
Is it possible to make Railo improvement?

Jay

unread,
Jul 29, 2011, 4:42:56 PM7/29/11
to ra...@googlegroups.com
you can control the capitalization of variables by using literal strings.

for example:

<cfset myVar = "value">

will cause the variable name to be "MYVAR"

but

<cfset "myVar" = "value">

will cause it to be "myVar"

same goes for structs (since all variables in CF are structs):

<cfset "myStruct.keyA" = "value a">

or

<cfset myStruct[ "keyA" ] = "value a">

will both cause keyA to be capitalized in the way it was written in the source code.

it Should affect the JSON but you should try it (and please let us know if it worked).


Jay



Serge Droganov

unread,
Jul 29, 2011, 5:07:21 PM7/29/11
to Railo
Hello Jay,
Yes it works with structs.
It's not so handy of course. But ok if response is rendered by me.
But what if the data is predefined. For example it is a form, or any
remote response?

Am I right, that letter case is not a matter of how SerializeJSON
works, but how Acf/Railo implement case insensitivity of variables?

Jay

unread,
Jul 29, 2011, 5:25:19 PM7/29/11
to ra...@googlegroups.com
if it's a FORM then there's a problem.

you can overcome it by creating a struct that defines the caseSensitive forms of variables, for example:

<cfset map = { FIRSTNAME="firstName", LASTNAME="lastName", EMAIL="email" }>

and then refer to the map to retrieve the correct capitalization when you construct your JSON or the struct that will be JSON-ized

Matt Quackenbush

unread,
Jul 29, 2011, 5:26:42 PM7/29/11
to ra...@googlegroups.com
It doesn't matter where the variable comes from.  Scopes in CFML are all just structs.  So you can always use bracket (array) notation to preserve cAsE.

form['apostvariable']
url['agetvariable']
session['asessionvariable']
client['aclientvariable']
cookie['acookievariable']
variables['alocalpagevariable']

You can also easily convert any incoming "unknown" variables to lower case.

mynewvariableholder = {};
for ( key in struct )
{
    mynewvariableholder[lcase(key)] = struct[key];
}

HTH

Serge Droganov

unread,
Jul 29, 2011, 5:32:26 PM7/29/11
to Railo
Sure Matt,
But this is a complication compared to just SerializeJSON(struct).

But anyway, for the problem is solved. We used such approach for the
xml attributes before.

Thank you!

On Jul 30, 1:26 am, Matt Quackenbush <quackfu...@gmail.com> wrote:
> It doesn't matter where the variable comes from.  Scopes in CFML are all
> just structs.  So you can always use bracket (array) notation to preserve
> cAsE.
>
> form['apostvariable']
> url['agetvariable']
> session['asessionvariable']
> client['aclientvariable']
> cookie['acookievariable']
> variables['alocalpagevariable']
>
> You can also easily convert any incoming "unknown" variables to lower case.
>
> mynewvariableholder = {};
> for ( key in struct )
> {
>     mynewvariableholder[lcase(key)] = struct[key];
>
> }
>
> HTH
>

Jay

unread,
Jul 29, 2011, 6:05:54 PM7/29/11
to ra...@googlegroups.com
Matt,

the question is not if you can Set a FORM variable, but rather if you can Read it in its original cAsE

sure you can Set form[ 'cAsE' ] but if in an html form (with method=post) you have

<input type="hidden" name="cAsE" value="Value">

then on the response cfm file you will get CASE and not cAsE as the variable name.

and if all you need is lower-case then I agree -- that's easy to fix.

Sean Corfield

unread,
Jul 30, 2011, 1:54:54 AM7/30/11
to ra...@googlegroups.com
On Fri, Jul 29, 2011 at 1:20 PM, Serge Droganov <design...@gmail.com> wrote:
> Does Adobe have a real reason for this?

To make CFML case-insensitive so that it is "easier" to write code -
without having to worry about getting everything "right". When
ACF/Railo see foo.bar they turn it into foo["BAR"] and the basic
"struct" in CFML is a variant of the standard Java HashMap that
uppercases keys before looking them up.

Yet another legacy of trying to remove the barrier to entry in a
language, I'm afraid, and being unable to break backward
compatibility.

> Is it possible to make Railo improvement?

Whilst I'm sure an Administrator option could be added that made
structs case sensitive, I bet money that such an option would break
pretty much all CFML written more than a few years ago :(

Now that I'm using Clojure extensively with CFML, I'm running into
this all the time. I've had to introduce a compatibility layer that
maps Clojure map keys to uppercase strings so that foo.bar works in
CFML (and vice versa). Fortunately Clojure's idiom is all
lower-case-with-hyphens so I can easily map between Clojure and CFML:
{ foo = 42, bar = "Hi!" } - which is really { "FOO" = 42, "BAR" =
"Hi!" } - becomes {:foo 42 :bar "Hi!"} in Clojure and vice versa.
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

Michael Offner

unread,
Jul 30, 2011, 3:49:31 AM7/30/11
to ra...@googlegroups.com
In Railo 1 every variable defined without " was lower case, simply because naturally more keys are lower than upper case, this makes a comparsion/conversion faster. But this has bring BIG problems with compatibility to ACF, because of that we have switched to uppercase in Railo 2.
Since Railo 3 we now no longer use strings for keys of structs, we now use objects from type Collection.Key. They are faster for comparison and they can keep the information of the source. In theory it is possible to have a flag in the admin that allow to define how this keys we are speaking about are converted:
How to handle keys ...:
- all upper case (ACF default)
- all lower case
- keep original case

We never have implement this because we think this brings more confusion than it helps

/micha

Vo mim iPhone gschickt

Serge Droganov

unread,
Jul 30, 2011, 6:13:14 AM7/30/11
to Railo
Hi Michael,
If it practically possible, why not to add cfdamin flag to make
variables case sensitive.
Place it after cascading option.

That would not affect old application, because default policy would
be, case insensitive variables.



On Jul 30, 11:49 am, Michael Offner <mich...@getrailo.com> wrote:
> In Railo 1 every variable defined without " was lower case, simply because naturally more keys are lower than upper case, this makes a comparsion/conversion faster. But this has bring BIG problems with compatibility to ACF, because of that we have switched to uppercase in Railo 2.
> Since Railo 3 we now no longer use strings for keys of structs, we now use objects from type Collection.Key. They are faster for comparison and they can keep the information of the source. In theory it is possible to have a flag in the admin that allow to define how this keys we are speaking about are converted:
> How to handle keys ...:
> - all upper case (ACF default)
> - all lower case
> - keep original case
>
> We never have implement this because we think this brings more confusion than it helps
>
> /micha
>
> Vo mim iPhone gschickt
>
> Am 30.07.2011 um 07:54 schrieb Sean Corfield <seancorfi...@gmail.com>:
> > Railo Technologies, Inc. --http://www.getrailo.com/

Todd Rafferty

unread,
Jul 30, 2011, 8:44:20 AM7/30/11
to ra...@googlegroups.com

He answered already:
"We never have implement this because we think this brings more confusion than it helps" <----
--
~Todd Rafferty
Volunteer
Community Manager
Railo Server - Open Source
----

Serge Droganov

unread,
Jul 30, 2011, 9:15:27 AM7/30/11
to Railo


On Jul 30, 4:44 pm, Todd Rafferty <t...@getrailo.org> wrote:
> He answered already:
> "We never have implement this because we think this brings more confusion
> than it helps" <----

Sure Todd, let's have a lot head ache because somebody thinks...
> ~Todd Rafferty*
> Volunteer** *Community Manager

Todd Rafferty

unread,
Jul 30, 2011, 11:19:03 AM7/30/11
to ra...@googlegroups.com
You'd be surprised of the number of features that have been pushed aside or something due to all the confusions. For example, originally OnApplicationStart() / OnSessionStart() didn't fire until the first declaration of a session / application variable. IMO a useful feature to prevent spiders from hammering your site too hard and taking up all the available memory and such. Too many people found it confusing, so it was reverted to ACF's implementation.

The more options we add to the Railo Administrator panels, the more confusing things are going to be. If you think this is a necessary enhancement, then open up a feature request over on uservoice and vote it up. http://railo.uservoice.com/
--
~Todd Rafferty
Volunteer
Community Manager

Serge Droganov

unread,
Jul 30, 2011, 11:43:21 AM7/30/11
to Railo


On Jul 30, 7:19 pm, Todd Rafferty <t...@getrailo.org> wrote:
> You'd be surprised of the number of features that have been pushed aside or
> something due to all the confusions. For example, originally
> OnApplicationStart() / OnSessionStart() didn't fire until the first
> declaration of a session / application variable. IMO a useful feature to
> prevent spiders from hammering your site too hard and taking up all the
> available memory and such. Too many people found it confusing, so it was
> reverted to ACF's implementation.
>
> The more options we add to the Railo Administrator panels, the more
> confusing things are going to be. If you think this is a necessary
> enhancement, then open up a feature request over on uservoice and vote it
> up.http://railo.uservoice.com/

I did. As for the bots one should probably design the apps better and
write robots.txt files or use load balancers. It has nothing to do
with Railo.

Michael Offner

unread,
Aug 2, 2011, 4:25:43 AM8/2/11
to ra...@googlegroups.com
when we publish the first Railo Alpha release (0.x) i had the impression that every problem with installation has nothing to do with Railo.
Railo is a Servlet and installation of a servlet is very simply, first install a servlet container and then add the servlet. 
i have learn very fast that this is just my view ...

/micha




2011/7/30 Serge Droganov <design...@gmail.com>
Reply all
Reply to author
Forward
0 new messages