XML to JSON

Description

XML to JSON (uv-t-xmlToJson):

This DPU transforms XML documents to equivalent JSON documents. The input and output is of type file.

Configuration Parameters

NameDescription
JSON Pretty PrintGenerates JSON documents, outputted in human readable format instead of compact machine readable format
Cast to JSON primitives automaticallyData types of XML elements are automatically detected and casted into corresponding JSON primitive types
XML element pathThe path of XML elements that should be parsed as a JSON array

Inputs and Outputs

NameTypeDataUnitDescriptionRequired
filesInputiFilesDataUnitXML documents to be transformed(tick)
filesOutputiFilesDataUnitJSON documents produced from transformation(tick)

XML Element to JSON Array

A sequence of XML elements with same element name can be considered as an array. However, there is no array structure in XML similar to JSON array, which means it is not prossible to decide if an element is actually an array with one object when there is only one element. Therefore, StAXON introduces some annotations to explicitly declare the XML elements that should be transformed into JSON arrays. Those annotations can be defined based on a XPath-like syntax path ::= '/'? <localName> ('/' <localName>)*.

For example:

<alice>
	<bob>edgar</bob>
</alice> 

are transformed to:

{
 "alice":{
  "bob":"edgar"
 }
}

By default with an annotation such as /alice/bob the result will become:

{
 "alice":{
  "bob":[
    "edgar"
  ]
 }
}

Reference

The core transformation engine of this plugin attributes to StAXON - JSON via StAX from Odysseus Software. For more information related to XML to JSON transformation, please visit StAXON WiKi.

Particularly, the following chapters are relevant to this plugin:

StAXON WiKi - Converting XML to JSON StAXON WiKi - Mapping Convention StAXON WiKi - Mastering Arrays