XML/JSON Conversion

The XML/JSON Action task converts an XML job file to JSON or a JSON job file to XML.

This task makes parsing XML/JSON files much simpler in a JavaScript environment and also allows processes to natively send JSON to a Connect template or data mapping configuration.

Input

The current job file.

Processing

The current job file is converted from XML to JSON or from JSON to XML. When converting from JSON to XML, the encoding of the resulting XML file is always set to UTF-8 (which is the default format for JSON).
The converted job file gets the appropriate extension (.JSON or .XML).

If the current job file isn't JSON or XML (depending on the type of conversion requested), or if the conversion fails for any reason, the task raises an error and the current job file and metadata remain unchanged.

JSON to XML conversion

When a JSON source file contains a single JSON object, that object's key will be used as the root node name in the resulting XML file, and the root node will be populated with the data inside of the JSON object. In all other cases, a root node named 'root' will be added to the XML. It has the property "OL" with the value "RootObject" to define it as an array container. This property will be ignored when converting from XML to JSON.

Note: In addition to being valid, the JSON should follow naming rules for XML elements. For example, "adress_line_1:" is a valid key name in JSON, but it cannot be converted to a valid element name in XML because the colon is reserved for namespaces. For XML naming rules and best naming practices, see: XML elements on W3Schools.

Output

The output is the modified job file, which replaces the input job file. The metadata are reset.

Task properties

General tab

  • Automatic detection: By default, the format of the job file is detected automatically. If the source file is a JSON file, it will be converted to XML. If it is an XML file, it will be converted to JSON.
    Uncheck this option to limit the task to one type of conversion.
  • JSON to XML: the task only converts JSON files to XML.
  • XML to JSON: the task only converts XML files to JSON.

On Error Tab

For a description of the options on the On Error tab see Using the On Error tab.

Miscellaneous Tab

The Miscellaneous tab is common to all tasks.

It contains a text area (Task comments) that lets you write comments about the task. These comments are saved when the dialog is closed with the OK button and are displayed in The Task Comments Pane.

Check the option Use as step description to display the text next to the icon of the plugin in the Process area.

The tab also provides an option to highlight the task in The Process area with the default color, set in the Preferences (see Colors), or the color selected or defined under Highlight color on this tab.
To revert the selected highlight color to the default color, open this tab, turn the Highlight option off and close the dialog with the OK button; then turn highlighting back on.
Highlighting can also be turned on and off via the task's contextual menu and with the Highlight button on the View ribbon.