The error just means your path is wrong, and the code is treating something as a structure that's actually just a string. While the data structure may be different than in your other thread, the concept of how to access values is the same. You just need to find the correct path to the desired keys. Keep in mind, JSON is a very simple format. It essentially consists of two object types: structures and arrays. So accessing ANY element just requires the correct series of key name(s) and/or array position(s).
Usually structure keys can be accessed with dot-notation. However, if the key names don't conform to CF's variable naming rules, you'll need to use associative array notation (or a mix of both):
someStructure.path.to.keyname <== dot-notation
someStructure["path"]["to"]["keyname"] <=== associative array notation
someStructure.path["to"].keyname <=== mix of both
street element
Accessing this element is very straightforward. The key name is a valid variable name, so it can be accessed with dot-notation. Since it's value is an array, you'll also need to supply a position if you only want a specific element within that array:
addresses.customer.street[1] <=== first element
addresses.customer.street[2] <=== second element
barcode element
Similarly, barcode
is a key within a nested structure. However, there are two differences. Some of the parent key names contain invalid characters (dashes), so you can't use dot-notation to access "barcode". Also, some of the parent keys appears to be dynamic:
items.{dynamic_uuid}.metadata.barcode
Since you won't know those ahead of time, the only way to access them is by looping through the parent structure (items
) keys dynamically and using associative notation:
<!--- demo structure --->
<cfset props = {items : {"#createUUID()#" : {metadata : {barcode :"759855743302"}} } }>
<cfloop collection="#props.items#" item="dynamicKey">
<cfoutput>
barcode = #props.items[dynamicKey].metadata.barcode#
</cfoutput>
</cfloop>