Using ACF 2021. I'm finally realizing (or re-remem...
# adobe
m
Using ACF 2021. I'm finally realizing (or re-remembering) that deserializejson is case insensitive. If I run that on structs with the same name, but didn't cases it doesn't return all the results. Example: https://cffiddle.org/app/file?filepath=5d84d5ae-1548-4f4b-898c-a84222367915/54b1ff0[…]ba8-8700-75c95b82d9be/dcd3814c-695d-4ab3-9089-10bdebe102c7.cfm. Is there any other best practice to deserializejson where case matters. I'm looping through millions of records so just trying to find the lowest overhead. Not seeing too much yet. My example is very small, but the actual data is much larger. I won't know the struct key names ahead of time.
d
Don't think the issue is with deserializeJSON(). By default ColdFusion structs themselves are case insensitive.
m
Right. I've seen some talk of dropping down into Java and trying to setup a hashmap.
d
I haven't looked into case sensitive structs, not positive, but there's probably a way to create one when the rest of the environment makes them case INsensitive.
r
Interesting info on Adobe's site for deserializeJSON(). ColdFusion (2025 release): Added the parameter preserveCaseForStructKey
👍🏻 1
m
I saw preserveCaseForStructKey on https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-c-d/DeserializeJSON.html. However it doesn't work in my version lol.. Doesn't really mention what version that is for.
r
It says 2025 release under the history section.
d
Works on my 2021 site.
m
@Dave Merrill I'm not creating these structs. I can only deserialize the json.
d
Hmmm, preserveCaseForStructKey didn't help?
r
That's not available until ACF2025 is released.
m
i'm on ACF 2021. it throws an error when i tried to use it.
d
Ugh.
Not what you're asking, but FYI, part of that page I pointed to is wrong, at least in 2021.
mystruct = *new* StructNew("casesensitive");
, which is in that doc, doesn't work,
mystruct = StructNew("casesensitive");
does.
m
i'm messing around trying to setup gson (https://mvnrepository.com/artifact/com.google.code.gson/gson). It's in my lib path, and i can see it's loaded, but still struggling getting some of the methods to work.
d
What about creating a case sensitive struct with a member x, and deserialize into there? Probably won't work, but it's worth a try.
r
Doesn't work. I tried that.
d
Nutz
m
Well. I finally got gson working! Here's at least one solution using a Java Library <cfscript> jsonString = "{ ""in"": [""value1""], ""In"": [""value2""] }"; gson = createObject( "java", "com.google.gson.GsonBuilder").*create*(); TypeToken = createObject("java", "com.google.gson.reflect.TypeToken"); typeofHashMap=TypeToken.*getParameterized*(createObject("java", "java.util.HashMap").*getClass*(),[createObject("java", "java.lang.String").*getClass*(), createObject("java", "java.lang.Object").*getClass*()]); result = Gson.*fromJson*(jsonString, typeOfHashMap.*getType*()); writeDump(var=result,abort=true,label=""); </cfscript>
👍 1
c
Here's a way to do it in CFML, assuming a few things about your data 🙂 and with no regard to performance against a large dataset 🙂 🙂 https://cffiddle.org/app/file?filepath=558c3412-58c5-4d89-ba40-8f6a1ae213ad/a541161[…]234-a998-1111852bd627/66f5dbf4-dd5f-463a-9aee-01242e16fe89.cfm Where is your dataset coming from? If a database, maybe your database can deserialize JSON for you (e.g., https://www.postgresql.org/docs/current/functions-json.html) and you can deal with as a normal query in CF. Would def be more performant than either solution.
d
"assuming a few things" indeed! (not directly related, but in the neighborhood, and classic: https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454?ref=blog.codinghorror.com#1732454)
🤣 1
c
Love it!