I have a script that received JSON data 99.9% of the time.
The data being sent typically contains 2 JSON log entries(rarely 1 or 3).
The script that takes the JSON post is pretty simple and just writes it to disk and then later on it gets parsed.
<CFIF CGI.CONTENT_TYPE EQ "APPLICATION/JSON">
<CFSET JSON_DATA = DESERIALIZEJSON(TOSTRING(GETHTTPREQUESTDATA().CONTENT))>
The result that is malformed looks like this:
The first long line(abbreviated) is correct JSON data but the second line ONLY contains a snippet from the end of the second packet.
I know that it is not an echo of the first line because sometimes that fragment is long enough to show values that are unique from the first line.
So, why is this happening?
Is there a better way to write the code for the receiver?
Is there a setting in JVM/CF that might make this work right?
It could be a random quote ("). Are you URLEncoding the values before putting them into a JSON array? If any of the values contain a quote, that could truncate the data according to JSON.
^ _ ^
I don't know yet if it will help but I've changed the code so that I only ready the structure once:
<CFSET VARIABLES.HTTP_REQUEST_DATA_CONTENT = GETHTTPREQUESTDATA().CONTENT>
<CFSET JSON_DATA = DESERIALIZEJSON(TOSTRING(VARIABLES.HTTP_REQUEST_DATA_CONTENT))>
If the data coming in is already JSON text, then you could just do something like
<cfif cgi.content_type eq "application/json" or cgi.content_type eq "application/x-www-form-urlencoded" or left(lCase(cgi.content_type),5) eq "text/">
<cfset json_data = gethttprequestdata().content>
<cffile action="write" file="#variables.user_interaction_output_directory#\#variables.user_interaction_output_file#_json_raw.log" output="#json_data#">