Situation:
We need to define JSON output as an Array that contains brackets [] whether it is a single record or multiple records. While using JSON schema, we have JSON as an array at the output only for multiple records at the source end. When we have some specific scenario where we need Array for the single record then we need to use custom class approach.
Expected
For Single Record :
{
"casetype_id":"abcdef-2dc5-4442-b636",
"requestor":{
"id":{
"kvk_number":123456789,
"branch_number":""
},
"type":"company"
},
"source":"webformulier",
"values":{
"ztc_locatie":[123],
"ztc_locatie_omschrijving":[570]
}
}
For Multiple Record :
{
"casetype_id":"abcdef-2dc5-4442-b636",
"requestor":{
"id":{
"kvk_number":123456789,
"branch_number":""
},
"type":"company"
},
"source":"webformulier",
"values":{
"ztc_locatie":[123,456,789],
"ztc_locatie_omschrijving":[570,571,572]
}
}
Solution:
- Download the attached file “XMLtoJSON.class” and place the file in the /ServerKernel/customClasses folder. Restart the Adeptia Server.
2. Create a custom plugin activity and copy the code below:
String keys = "key1,key2";
new XMLtoJSON().convertData(keys,inputStream,service);
Define the list of keys separated by the comma for which you want the corresponding values to be treated as an array while creating the JSON file. As an example in our use case, Keys would be the items as shown below:-
String keys = "ztc_locatie,ztc_locatie_omschrijving";
- In process flow remove JSON schema after the mapping activity and place Custom Plugin activity created in step 2. Make sure that stream name is "default" in the Multiple Stream coming from custom plugin to the JSON target activity.
- Execute the process flow
Note: The XMLtoJSON zip file is Adeptia Suite version dependent. Also, the latest i.e. XMLtoJSON_After_6.8 class file is faster in terms of processing.
Comments
0 comments
Article is closed for comments.