I've given up and just do this: `JSON.parse(respon...
# suitescript
m
I've given up and just do this:
JSON.parse(response.data.replace(/<!--(.*?)-->/g, ''))
s
@michoel I ran into this as well in the past. Here's how I found to fix it:
context.response.setHeader({ name: 'Content-Type', value: 'application/json', }); context.response.write(...);
If you set the Content-Type to application/json, it stops adding the commented out block to the end of the response when the response contains some special keywords
m
I'm pretty sure I tried that, also I had it working for a while and one day it just broke without touching
s
I haven't run into any issues so far with that approach
m
Good to know but to be honest I don't have much faith in NetSuite not breaking it again so I think I'll like the replace in my code for now
What do you mean by "contains some special keywords" though?
s
for example, if you return json like this without setting the Content-Type to application/json, no commented out block is added to the response by NS
Copy code
{
  "test": "test"
}
but if you were to return {"test":"<html></html>"}, NS adds in the commented out block in the response.
not really sure what keywords / patterns trigger it, but html tags do it.
m
Interesting, thanks
s
np
m
I am also pretty sure they've made changes to this behavior around April this year, looking at my git history that's when I had to adopt this hack on one project that was working perfectly fine until then
s
I ran into this back in Jan and that's when I started setting the Content-Type
It's an odd feature - I'm guessing there's something sitting in the middle looking for html-ish responses and adding the comment block to the end.
e
Thanks @Seth Duda for the tip - most likely these offending records contained html tags that were included in the JSON response. I’ll look into setting the Content Type explicitly