Parsing JSON request on monolith application

Hello,

I am using Lucee as monolith application (not as API service with mapping). When I am sending POST HHTP request to function in .cfc component with method=functionName, if I want to receive that JSON data I must use this trick:
<cfset var dataStruct = deserializeJSON(toString( getHttpRequestData().content ))/>
I am proposing to create deserializeJSON(toString( getHttpRequestData().content )) as standard Lucee function, or to have some more elegant solution.
Sorry if this already exist.

toString() shouldn’t help. Have you tried taking it off?

1 Like

Hi @Aleksandar_Petrovic JSON is a string per se. You usually don’t need to convert it again to a string, because it’s already one. I think what you are receiving in your getHttpRequestData().content isn’t a JSON, maybe something else… you end point (or client) may not be properly configured to be receiving/sending JSON objects. Can you check if your Mime-Type or Content-Type is getting/sending “application/json” in that request? How are you getting the data to your end point (client)? I think he isn’t sending the data as JSON.

See here:

1 Like

I think that such a standard function is unnecessary. It will be making assumptions about the request data.

Here is a suggestion, along the lines of what @andreas said:

 <cfif isJson(getHttpRequestData().content)>
     <cfset var dataStruct = deserializeJSON(getHttpRequestData().content)/>
 <cfelse>
     <!--- Handle the case where getHttpRequestData().content is not JSON>
 </cfif>
2 Likes

I have checked in Lucee 5.4.3.2 it works fine without of toString, and also work fine with it. In CF10 it doesn’t work with out of toString, as it returns bytes. When I am sending data with POST request using jQuery function serialize, as key=value& etc. all variables are inside of the component with out of my handling. Only when I am sending JSON I have to do manually from getHttpRequestData().

It sounds like you’re on your way so I would only add that I believe in CF 2018 is when they changed something major as far as data-types. Meaning that strings had to be strings and numerics had to be numeric where is legacy ColdFusion anything before 2018 would handle everything as a string or so I’m told…

I never really bothered with it. Because I’m mostly Lucee now. At the moment I am in the middle of a conversion to Linux (I know I’m late to the party) but I finally understand the decision to be case sensitive. When I am setting up Apache ( many thanks to Andreas for those videos on YouTube) now I have to install an uppercase to lowercase converter for applications on bringing over to Linux.

This created the overhead I had never accounted for in the uppercase to lowercase scenario. But I understand this decision as far as : to get on the field to get everyone as fast as possible - Microsoft and other platforms must have decided to convert case to make it more convenient for humans while at the same time creating apparently a devastating amount of overhead.

Since I’ve been on Linux my application page times have you dropped insanely. On the same exact machine… I’m seeing response times of 60 ms or less versus around 180-240 in IIS. I mean I’ve got a really press apache hard to get it above 30 ms. I knew that Linux is faster but I wasn’t expecting that much.

And I know this is much more of an answer than you asked for but I thought I would impress upon anyone reading how devastating the overhead of IIS is.

what’s the overhead on a echo(“hello world”); type .cfm file?

sounds like you might be hitting the old ipv6 / ipv4 problem, where it tries one before falling back to the other?

@Jay.MC thank you so much for posting that. Its very pleasant receiving such a nice feedback.

Hey Zack I thought about that and this is not that (the persistent 1 second delay on windows based systems). Actually that was my motivation for going to Linux for my workstation (among other things).

My latest install of Lucy on windows(server) resulted in the 1 second delay and this time I couldn’t get around it by the usual tweaks in server.xml … address=“::1” … etc… That in combination to the imminent threat of windows 11/12 and beyond I’ve finally dumped windows for good and recreated a better faster setup on linux.

Lucee speeds are incredible : sometimes as low as 7ms and that includes hitting a DB on a local VM generating ap page listing around 100 rows. It’s an ubuntu based distro named Zorin OS. I don’t want to junk up the forum by going on about it but I would recommend it for anyone who has had enough of MS windows heavy handedness dragging down their day.

However I would be willing to post a video here for anyone interested in making the switch. Here is a screenshot of my desktop. I have all the usual tools for coding browsing and of course all the usual development assets are possible and far faster without the windows overhead.

1 Like