AnsweredAssumed Answered

How to split JSON string values and map it to a JSON Array elements

Question asked by amudhavani.shanthosh181426 on May 23, 2018
Latest reply on May 24, 2018 by SaiKumarGoud Mallari



The requirement is as follows :

Both Source and Destination profile are in JSON format.

The JSON source profile has a string field with value ""Xray;A P CAP 250MG"

It needs to be mapped to the destinaton JSON profile element which is of type Array (Repeating) in the following format

["Xray","A P CAP 250MG"]


I tried the below script in the Data Process Shape and the output of the data process shape is as follows :

Xray,A P CAP 250MG


I stored the above output in a set property shape to a DPP as "current data". And mapped this DPP in the map shape to the destination profile Array element and the output is as follows :


"SecD11" : [
"Xray,A P CAP 250MG"

^^ which is an incorrect Array format. 


Can you please help me in splitting the JSON string elements and adding it to the JSON Array elements. Thanks.


Code done in the data process shape :


import java.util.Properties;
import com.boomi.execution.ExecutionUtil;
import java.text.*;

logger = ExecutionUtil.getBaseLogger();

String LINE_SEPARATOR = System.getProperty("line.separator");

for( int i = 0; i < dataContext.getDataCount(); i++ ) {

InputStream is = dataContext.getStream(i);
Properties props = dataContext.getProperties(i);

BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuffer outData = new StringBuffer();
int lineNum = 0;

while ((line = reader.readLine()) != null) {

String[] eachString = line.split(";");

int numberOfDates = eachString.length;"numberOfDates: " + numberOfDates);

String res = "";
for(int j=0;j<numberOfDates;j++){


// Convert the output StringBuffer to an InputStream and store in the dataContext
is = new ByteArrayInputStream(outData.toString().getBytes("UTF-8"));
dataContext.storeStream(is, props);