ItineraryStep - Json
The JSON assembler is a system artifact in Link 3.0. Its purpose is to convert XML documents to JSON files prior to sending them to a recipient.
Configuration
The JSON assembler configuration looks like this:
Only the fields in the “Settings” section are specific to the assembler.
Include XML Root Node
By default the XML root node is omitted. Set this checkbox to include it in the generated JSON.
Include XML Namespaces
By default XML namespace declarations are omitted. Set this checkbox to include them in the generated JSON.
Use Indentations
By default the JSON structure will be generated as a one line string with no spaces or line breaks. Set this checkbox to generate more human readable JSON with line breaks and indentations.
Data annotations
By default all values from the input XML will be treated as string values when converted to JSON.
However it is possible to use a type attribute on a XML tag to tell the assembler how to represent the value in JSON.
The following types are supported:
Integer
Float
Boolean
Array (2024-01-19: Obsolete in future releases. Use attribute array instead)
Date
Important: Remember to declare the namespace used for the type and array attributes. The namespace must be “http://bizbrains.com/json
“ The namespace prefix used in the example is “json” but can be anything.
Arrays
2024-01-19: Obsolete in future relases:
XML tags with the same name will by default be parsed as elements of an array. To be sure also a single XML tag wil be parsed as an array with one element, use the type=”array” attribute on the XML tag.
For releases after 2024-01-19
XML tags with the same name will by default be parsed as elements of an array. To be sure also a single XML tag wil be parsed as an array with one element, use the array=”true” attribute on the XML tag.
Example
XML:
<BrandCatalog xmlns="http://company.com" xmlns:json="http://bizbrains.com/json">
<Brands>
<BrandId json:type="integer">1</BrandId>
<Name>Mercedes-Benz</Name>
<MultiBrand json:type="boolean">false</MultiBrand>
<Value json:type="float">123.4</Value>
<AltNames json:array="true">
<Id json:type="integer">1</Id>
<name>MB</name>
</AltNames>
</Brands>
<Brands>
<BrandId json:type="integer">2</BrandId>
<Name>Volkswagen</Name>
<MultiBrand json:type="boolean">true</MultiBrand>
<Value json:type="float">234.5</Value>
<AltNames>
<Id json:type="integer">1</Id>
<name>VW</name>
</AltNames>
<AltNames>
<Id json:type="integer">2</Id>
<name>VAG</name>
</AltNames>
</Brands>
</BrandCatalog>
JSON:
{
"BrandCatalog": {
"Brands": [
{
"BrandId": 1,
"Name": "Mercedes-Benz",
"MultiBrand": false,
"Value": 123.4,
"AltNames": [
{
"Id": 1,
"name": "MB"
}
]
},
{
"BrandId": 2,
"Name": "Volkswagen",
"MultiBrand": true,
"Value": 234.5,
"AltNames": [
{
"Id": 1,
"name": "VW"
},
{
"Id": 2,
"name": "VAG"
}
]
}
]
}
}