JsonCreationUnit
Class name |
com.ebd.hub.datawizard.iu.JsonCreationUnit |
This Integration Unit is deprecated. Please use the "ExtendedJsonCreationUnit" for newly developed profiles.
This Integration Unit generates a JSON document out of the target tree.
The encoding of the file is always UTF-8. Each record creates an object {content}. Multiple records are written into a list [{content1},{content2}].
If the target structure node attribute "XML/JSON handling" is set to Exclude, the JsonCreationUnit will not process the node.
Numbers after a # in field and node names are ignored during the JSON generation. See the creation of arrays below.
Parameters
Parameter name |
Allowed values |
Default value |
Description |
Decode unicode values |
true, false |
false |
If false, certain characters (e.g. ", <, >) are replaced by Unicode escape sequences. If true, this is not done, except for the " character, which is replaced by \u0022. |
Escape < and > |
true, false |
false |
The characters < and > are escaped by this Integration Unit. The result is < und > This option should be set to true if the Integration Unit is used for Forms. This can prevent JavaScript injection. |
Force array creation for nodes with max > 1 |
true, false |
true |
If true, nodes with Maximum > 1 will always create an array, even if the nodes were only entered once. |
Pretty print |
true, false |
false |
If true, the JSON file is formatted. |
Resolve OData names |
true, false |
false |
A name like @company.com would be allowed in JSON but is escaped in this Integration Unit. The result would be __at__company__dot__com If you do not want those characters to be escaped, set the option to true. |
Start at node |
<nodeName> |
|
If a node name is set, the creation of the JSON file starts with this node. Without node name, the complete tree is created. |
Use description as field/node name |
true, false |
false |
If set to true and the field/node attribute Description has a value, the value of the attribute is used instead of the field/node name in the JSON file. |
Use transparent nodes |
true, false |
false |
If true, the target node attribute "XML/JSON handling=Transparent" will be considered. See the notes below in the example. |
Write empty fields not as null |
true, false |
false |
If true and parameter Write empty/null field values is also true, value "" will be used instead of value null. |
Write empty/null field values |
true, false |
false |
If true, fields with set Empty Flag will be included in the JSON document with value null. See also parameter Write empty fields not as null. |
Write top level nodes as objects |
true, false |
true |
If true, all nodes on root level will create separate objects, e.g. {"node_name":{"content"}}. If false, the content of those nodes will be written directly. |
Write values type safe |
true, false |
false |
If true, fields of type Integer, Float, Double, BigInteger, BigDecimal and Boolean will not be written in quotes. Important note: This setting has no effect if a template is used. |
Example
The following target tree is used to create a JSON document.
If the parameter Write top level nodes as objects is set to true, the following file will be created.
{"Invoice":
{
"invoice_no":"4711",
"iln_buyer":"400000045687",
"iln_supplier":"123456789",
"delivery_no":"0815",
"item":[
{"article_no_supplier":"87490","EAN":"3654878784","content":"Sausage","unit":"pcs","quantity":"200","item_no":"1","price":"30","vat_rate_item":"19"},
{"article_no_supplier":"8786767","EAN":"546546","unit":"pcs","quantity":"1","item_no":"2","price":"56"}
],
"invoice_no":"08154711",
"vat_rate_1":"19",
"vat_rate_2":"7",
"currency":"EUR"
}
}
If the parameter Write top level nodes as objects is set to false, the file will look like this.
{
"order_no":"4711",
"iln_buyer":"400000045687",
"iln_supplier":"123456789",
"delivery_no":"0815",
"item":[
{"article_no_supplier":"87490","EAN":"3654878784","content":"Sausage","unit":"pcs","quantity":"200","item_no":"1","price":"30","vat_rate_item":"19"},
{"article_no_supplier":"8786767","EAN":"546546","unit":"pcs","quantity":"1","item_no":"2","price":"56"}
],
"invoice_no":"08154711",
"vat_rate_1":"19",
"vat_rate_2":"7",
"currency":"EUR"
}
Transparent nodes
Nodes marked blue have the target structure node attribute "XML/JSON handling=Transparent".
Following the results depending on the Integration Unit parameter "Use transparent nodes".
Target tree |
Result (Use transparent nodes = true) |
Result (Use transparent nodes = false) |
|
|
|
The same transparent node must not be created multiple times. If that happens, the Integration Unit aborts with an error. Note: For transparent nodes with the attribute maximum > 1, a warning is output in the log.
Target tree |
Result (Use transparent nodes = true) |
Result (Use transparent nodes = false) |
-->
|
Error: transparent node 'TransparentNode_Error' may not have more than one iteration |
|
However, it is possible to use multiple transparent nodes. As you can see in the example, the values of fields with the same name are then summarised (as you already know: value#1 and value#2 become value in the JSON document). Note: This is effectively an array (see below).
Target tree |
Result (Use transparent nodes = true) |
Result (Use transparent nodes = false) |
|
|
|
Arrays
An array can be created by using single fields with the same name. Everything after the # in the field name will be ignored. So ArrayValue#1-3 becomes ArrayValue.
Target structure |
Result |
|
|
Alternatively, simple arrays/lists can be generated with a node/field combination. The node may only contain one field. The field name has to be like the node name plus the suffix _val. The node is traversed several times. Important note: This does not work with several nodes of this kind. So if there were a node MyArray and further down in the structure another node MyArray#2, then the mechanism described would only work for the first node MyArray.
Target structure |
Result |
|
|