How to convert an XML payload into JSON in ServiceNowSummaryWhen integrating ServiceNow with third-party applications, some external systems may respond with payloads in XML format. While ServiceNow supports parsing XML payloads, working with JSON is often more convenient and widely preferred. This article provides a step-by-step guide on converting a web service's XML response payload into a JSON object for seamless usage within ServiceNow. Note: When converting data from XML to JSON, the order of data elements may vary. However, all data elements from the XML payload will be preserved and accessible in the JSON format.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()); //Prints XML Response payload var jsonObj = gs.xmlToJSON(res_body); // Converting XML into a JSON object gs.print('\n\nNumber: ' + jsonObj.response.result.number); var str = JSON.stringify(jsonObj); // Converting JSON object into a String gs.print('\n\n JSON Payload: \n' + str); //Prints JSON Payload though, } doIt();