Skip to main content
Apr 8, 2011 7:43 AM UTC
Question

Structure using bracket notation

I am using cf8 and tried to create a structure using bracket notation

like this.

<cfset struct_sample = {"foo" = "bar"} />
<cfdump var="#(struct_sample)#" />

But its showing error near the opening bracket as 'Invalid CFML construct found' . If i write without quotes like this  <cfset struct_sample = {foo = "bar"} />

it works fine, but it converts the key to uppercase. I need it in lowercase since it needed to converted to json format.

Can anybody explain what is wrong with the first syntax?

    This topic is closed to new replies. Start a new post to keep the conversation going.

    2 replies

    Owainnorth
    Inspiring
    Apr 8, 2011 7:53 AM UTC

    I believe I'm right in saying that if you ever want a key name in lower case or with special chars you have to use the specific bracket notation, as it's the only method that allows you to enter a key name in quotes:

    <cfset sample = {} />
    <cfset sample["foo"] = "bar" />
    <cfdump var="#sample#">

    Although to be honest you might just be better off creating your json string then lowercasing it afterwards rather than limiting what CF methods you can use.

    Translate
    Inspiring
    Apr 8, 2011 7:47 AM UTC

    You're quoting the key name as well as the value...

    --

    Adam

    Translate