Skip to main content
April 8, 2011
Question

Structure using bracket notation

  • April 8, 2011
  • 2 replies
  • 404 views

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 has been closed for replies.

    2 replies

    Owainnorth
    Inspiring
    April 8, 2011

    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.

    Inspiring
    April 8, 2011

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

    --

    Adam