I try to convert my wso2 aggregated list of list response into single list. But script mediator doesnt work. so i try with custom mediator. That mediator function is,
public void process(MessageContext mc) {
String s = (String)mc.getProperty("data")).toString();
ArrayList<String> list = new ArrayList<String>();
JSONArray jsonArray = new JSONArray(s);
if (jsonArray != null) {
int len = jsonArray.length();
int len2 = 0;
JSONArray j2;
for (int i=0;i<len;i++){
j2 = new JSONArray(jsonArray.get(i));
len2 = j2.length();
for (int j=0;j<len2;j++){
list.add(j2.get(j).toString());
}
}
}
mc.setProperty("data", list.toString());
}
but when i use it there is an error. Are there any possible way to do this. without using custom mediator. Basically my "data" parameter value something like this,
[
[{'a1':12,'b1':'sd'},
{'a1':12,'b1':'sd'}],
[{'a1':12,'b1':'sd'},
{'a1':12,'b1':'sd'}],
[{'a1':12,'b1':'sd'},
{'a1':12,'b1':'sd'}]
]
what i need after the mediation is,
[
{'a1':12,'b1':'sd'},
{'a1':12,'b1':'sd'},
{'a1':12,'b1':'sd'},
{'a1':12,'b1':'sd'},
{'a1':12,'b1':'sd'},
{'a1':12,'b1':'sd'}]
Please help me.