Hey folks I've got a json object returning enormou...
# cfml-general
j
Hey folks I've got a json object returning enormously long names for fields that deserialize fine but when I ask structKeyExists(jsonobj,'superlongfieldnamewithwaytomuchinformation'). What is the limit on the key name and anyone find a work around (this one is 46 characters long).
m
Does it error when you "ask"? What's the error say?
j
key doesn't exist
m
Does it show when you dump the object?
screenshot?
j
Element WHATTYPEOFPROFESSIONALSERVICESDOYOUPROVIDE___C is undefined in a CFML structure referenced as part of an expression.
Oh yes the object dumps
roW_NUMBERundefinedwhattypeofprofessionalservicesdoyouprovide___cstructaccessLevel20
m
^^what's
roW_NUMBERundefinedwhattypeofprofessionalservicesdoyouprovide___cstructaccessLevel20
?
j
sorry
m
How are you providing the key to
structKeyExists()
? Seems like it could be a typo.
j
the fetch is based on an argument
cfif structKeyExists(jsonObj.columnMetadata,'#arguments.customField#')
also it dumps if I use dot notation with that specific variable
but dot notation does't work with variables
using jsonObj.columnMetadata['#arguments.customField#']
cf21 is the server
m
What exactly are you dumping in the screenshot? In the screenshot and your original question, it seems that
whattypeofprofessionalservicesdoyouprovide___c
is in the top-most level (directly inside whatever you dumped:
structKeyExists(jsonobj,'superlongfieldnamewithwaytomuchinformation')
), but your subsequent code snippets,
structKeyExists(jsonObj.columnMetadata,'#arguments.customField#')
, indicate a lower level,
jsonObj.columnMetadata
.
j
I'm dumping columnMetadata
The first question was a simple summary that didn't show exactly what I was working on
m
I'm not aware of any struct key length restrictions
j
because the issue is likely the key and the other information is irrelevant and distraction
a
j
????
m
is
arguments.customField
exactly the same as the key in the struct? I'm still learning toward typo or checking the wrong struct level
j
yes
a
I'm assuming you dumped out
jsonObj.columnMetadata
in your screenshot?
j
<cffunction name="getCustomFieldMetaData">
<cfargument name="customField" type="string" required="true"> <cfoutput> <cfsavecontent variable="variables.jsonbody"> { "msql": "select #arguments.customField# from Individual where (#arguments.customField# <> '')", "page": 0, "pageSize": 1 } </cfsavecontent> </cfoutput> <!--- <cfdump var="#variables.jsonBody#"><cfabort> ---> <cfhttp url="#BaseUrl#/search/executeSearch" method="post"> <cfhttpparam type="header" name="Content-Type" value="application/json"> <cfhttpparam type="header" name="authorization" value="#accessToken#"> <cfhttpparam type="body" value="#variables.jsonBody#" /> </cfhttp> <!--- <cfdump var="#cfhttp#"><cfabort> ---> <cfset jsonObj = deserializejson(cfhttp.filecontent)> <cfset customMeta = jsonObj.columnMetadata> <cfdump var="#customMeta#"> <cfif structKeyExists(jsonObj.columnMetadata,'#arguments.customField#')> extensionExists <cfelse> doesn't exist </cfif> <cfset retArray = arrayNew(1)> <!--- <cfdump var="#retStruct#"><cfabort> ---> <cfset arrPickList = jsonObj.columnMetadata['#arguments.customField#'].pickListEntries> <cfloop from="1" to="#arrayLen(arrPickList)#" index="i"> <cfset temp=arrayAppend(retArray,arrPickList[i].value)> </cfloop> <cfreturn retArray> </cffunction>
this is messy also msql != sql (in this particular API)
a
right - so is the
arguments.customField
value all lowercase?
j
It is not
a
OK - so in CFML the case of keys is not important, but if that 'struct' is actually a java map object then case does matter.
m
cf isnt' typically case-sensitive, though. At least not for
structKeyExists
@aliaspooryorik gotcha
a
worth a try anyway
j
thx all, misspelled
👍 1
trim the var