Created on 08 May 2018
icon_unfollowing
Login to follow
xmltojson

XmlToJson

Stable version 1.0.2 (Compatible with OutSystems 11)
Other versions available for 10
Uploaded on 30 November 2022 by 
xmltojson

XmlToJson

Documentation
1.0.2

XmlToJson

Introduction

XmlToJson is a simple extension that allows the programmer to convert an XML document to the equivalent JSON. This makes it easier to deal with the data in OutSystems, as it's much easier to deal with JSON than XML.

Since version 1.02 it is possible to specify the (local) node names that are to be treated as arrays, even if the XML contains only a single element. This will help with situations where you may sometimes have a single element and sometimes multiple. Without specifying the node to be treated as an array, the JSON will sometimes contain an object, sometimes an array of objects, which means you cannot convert the JSON to a structure easily.

The extension uses NewtonSoft.Json's JsonConvert.SerializeXmlNode function for the heavy lifting, meaning that any limitations this asset has are due to that function.

Converting XML to JSON

The extension has a single action, XmlToJson (in version prior to 1.02 this was called toJSON), that has the following parameters:

  • XML - input parameter of type Text that contains the XML document. It must be valid XML, or it cannot be parsed. Note that any namespaces are parsed as well and included in the JSON. Any attributes are included as well, with an "@" in front of the name;
  • ArrayNodes - optional input parameter of type list of "Node" structures. The "Node" structure contains a single attribute "Name". If specified, each node in the XML document that has a local name that is equal to one of the node names in the list will become an array in the output JSON;
  • JSON - output parameter of type Text that contains the converted JSON.


The resulting JSON can be used to create structures from (design time), then serialized (run time). This is much easier than trying to serialize the XML.


Support options
This asset is not supported by OutSystems. You may use the discussion forums to leave suggestions or obtain best-effort support from the community, including from  who created this asset.
Dependencies
XmlToJson has no dependencies.