I am trying to output a query object as JSON. I found some code that suggested using the ColdFusion cfscript
tag along with the serializeJSON
function:
<cfscript>
theJSON = SerializeJSON(queryObj);
writeOutput(theJSON);
</cfscript>
This works to create JSON from the query object. However at the end of the outputted json is an xml comment is always appended like this:
{"COLUMNS":["ID","VALUE"],"DATA":[["12345","abcd"]]} <!-- 113760 -->
The number inside the xml comment always being randomly generated. Because this is xml it is not valid json. I would like to get rid of it but I am not sure how. Any ideas why this xml is showing up or how I can get rid of it?
Most likely you have something else outputting that comment. Make a separate file with a query and the code you posted. Run the code and see if you still have same issue. Make sure to look in Application.cfm
or Application.cfc
files if you have those in your context.
Also you can try inserting abort
into your code to see if the problem is still there:
<cfscript>
theJSON = SerializeJSON(queryObj);
writeOutput(theJSON);
abort;
</cfscript>