How to convert an XML payload into JSON in ServiceNowSummaryWhen integrating ServiceNow with 3rd party applications, some applications respond with XML payload only. Though, we can parse an XML payload as well in ServiceNow but using JSON is more popular. This article explains how to convert a web service XML response payload into JSON Object and use it accordingly.ReleaseAllInstructionsThe use case here is making a REST API call to a ServiceNow instance, retrieve the response in XML and convert it into JSON and then use it. Please use this script as a reference and modify it as per your needs: function doIt() { var request = new sn_ws.RESTMessageV2(); request.setEndpoint('https://instance.service-now.com/api/now/table/incident/sys_id'); request.setHttpMethod('GET'); var user = 'user_name'; var password = 'password'; request.setBasicAuth(user, password); request.setRequestHeader("Accept", "application/xml"); var response = request.execute(); var res_body = response.getBody();// XML Response //gs.print('XML Response:\n\n' + response.getBody()); var jsonObj = gs.xmlToJSON(res_body); // Converting XML into a JSON object gs.print('Number: ' + jsonObj.response.result.number); //var str = JSON.stringify(jsonObject); // Converting JSON object into a String } doIt();