Has anyone figured out a good way to intuit whethe...
# suitescript
r
Has anyone figured out a good way to intuit whether a string is HTML or JSON? My problem is that sometimes an external API sends JSON in the response body. Sometimes it's HTML.
e
put a try/catch around JSON.parse. if it fails, it’s not JSON.
👍 2
👍🏻 1
t
Haven’t tried this, but just wondering if something like
Copy code
serverResponse.getHeader({
    name: 'Content-Type'
});
could work? My assumption is this should return application/json in case of JSON, and text/html (something similar like xml) in case of html
👍🏻 1