XML to JSON
XML to JSON
This DPU transforms XML documents to equivalent JSON documents. The input and output is of type file.
Name | Description |
---|---|
JSON Pretty Print | Generates JSON documents, outputted in human readable format instead of compact machine readable format |
Cast to JSON primitives automatically | Data types of XML elements are automatically detected and casted into corresponding JSON primitive types |
XML element path | The path of XML elements that should be parsed as a JSON array |
Name | Type | DataUnit | Description | Required |
---|---|---|---|---|
filesInput | i | FilesDataUnit | XML documents to be transformed | |
filesOutput | i | FilesDataUnit | JSON documents produced from transformation |
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" ] } }
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