8 Replies Latest reply on Sep 25, 2010 8:46 AM by msoultan

    How to access a JSON structure key that starts with a number


      I've got an odd issue here.  I'm accessing someone else's JSON structure so I am not able to change it.  The JSON structure keys are named with both characters and numbers like this:




      1Rashaan Houston feat Tony Loreto
      artistRashaan Houston feat Tony Loreto



      So, in other words, there's a key named "0" and a key named "product_id", both of which contain the same key.  Why they did that, I don't know, but they did.


      In one of the instances, the data stored under the text-named key isn't the same as the numerical-named key.  I tried to output the data in the numerical key like this (it's an array of structures):




      but I get the following error:



      Invalid CFML construct found on line 41 at column 31.

      ColdFusion was looking at the following text:





      When I do the following, it works fine:





      So it looks as though CF doesn't like accessing a variable that starts with a number.  I am able to loop through the structure using a collection loop, and it outputs all of the keys (including the numerical ones) and their values using the following code:


      <cfloop collection="#strStompyJSON.data[1]#" item="key">
      #key#: #strStompyJSON.data[1][key]#<br />



      However, that doesn't allow me a way to access specific keys named with a number.  Is there a way that I can specifically access a key that is named with a number?