convertPayloadToXML

A Workflow Engine function that converts a JSON payload to an XML string using the Moobot utility jsonToXML. This function is intended for payloads created using the getPayload() action. The resulting XML replaces the payload for use in subsequent actions.

Note

If the payload requires other XML attributes, you should add these as JSON keys before the workflow converts the XML payload.

This action does not escape XML restricted characters (e.g. > and < to < >). Make sure that all values are XML safe before running this action.

This function is available as a feature of the Add-ons v2.3.5 download and later.

This function is available for event, alert, and Situation workflows.

Back to Workflow Engine Functions Reference.

Arguments

Workflow Engine function workflowEngineFunction takes the following arguments:

Name

Required

Type

Description

value

Yes

JSON object

The JSON object to convert to XML.

Example

To set up a workflow to send an XML payload rather than the standard JSON, do the following:

  1. Verify that the REST endpoint supports a Content-type appropriate for an XML payload: text/xml, application/xml, etc.

  2. Include the following actions in the relevant workflow:

The following example code demonstrates typical use of the jsonToXML method:

var jsonObjectExample =
{
  "data": {
    "alerts":
    [
      {
         "enriched": "false",
         "id": "1",
         "description": "Alert 1",
         "host": "email.moogsoft.com",
         "severity": "5"
      },
      {
         "enriched": "true",
         "id": "2",
         "description": "Alert 2",
         "host": "calendar.moogsoft.com",
         "severity": "2"
      }
    ]
  }
};

var convertedXML = utilities.jsonToXML(jsonObjectExample);

The variable convertedXML now contains:

<data>
   <alerts>
      <severity>5</severity>
      <enriched>false</enriched>
      <host>email.moogsoft.com</host>
      <description>Alert 1</description>
      <id>1</id>
   </alerts>
   <alerts>
      <severity>2</severity>
      <enriched>true</enriched>
      <host>calendar.moogsoft.com</host>
      <description>Alert 2</description>
      <id>2</id>
   </alerts>
</data>