ExtendedJsonCreationUnit
Group |
|
Class Name |
com.ebd.hub.datawizard.iu.ExtendedJsonCreationUnit |
Function |
This Integration Unit generates a JSON document from the destination tree. It is a variation of the JsonCreationUnit. |
Description
Introduction: Integration Units.
The class JsonCreationUnit generates a JSON document out of the destination 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 destination 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.
Parameter Description
Parameter Name |
Allowed Values |
Default Value |
Description |
Enable '_name' field handling |
true, false |
false |
See parameter Use description as field/node name. |
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 the Portal. This can prevent JavaScript injection. |
Pretty print |
true, false |
true |
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> |
|
(mandatory) If a node name is set, the creation of the JSON file starts with this node. |
Use description as field/node name |
true, false |
false |
If true, the value of attribute Description is used as node/field name. Note: If you want to rename a node during runtime, you can use a field with suffix _name to rename its parent node. The name of the JSON object is no longer determined by the name of the parent node but the value of the field (not name). The field name needs a prefix that is equal to the name of the parent node that shall be renamed. So if you want to rename parent node POS, you have to use field name POS_name. Important note: Parameter Enable '_name' field handling must have the value true for this. Note: You cannot use this method to rename the top level node (root node). Note: If a node is used to create an array (see node MyArray in the examples below), the field value of MyArray_name of the last iteration is used. |
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 values type safe |
true, false |
true |
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 destination tree is used to create a JSON document.
The top-level node is always represented as an object (this behaviour can be configured in the JsonCreationUnit).
{"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"
}
}
Transparent Nodes
Nodes marked blue have the destination structure node attribute XML/JSON handling=Transparent.
Destination Tree |
Result |
|
|
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.
Destination Tree |
Result |
-->
|
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).
Destination Tree |
Result |
|
|
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.
Destination 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.
Destination Structure |
Result |
|
|
If you want to create an unnamed array this way, node MyArray must be in a parent node with destination structure node attribute XML/JSON handling set to Array. The node MyArray itself can have the attribute value Array, Normal or Transparent.
Destination Structure |
Result |
|
|
If you also want to remove the parentheses of the array to get only the values, you can set the destination structure node attribute XML/JSON handling of node MyArray to Array Transparent.
Destination Structure |
Result |
|
|
Note: You can also use the last two methods to create nested arrays, which is not possible with the first two methods.