I am trying to use java code in my VSM which creates dynamic JSON payload
The code is as below:
public class json {
public static void main(String[] args) throws Exception {
String FNNOrg = "123,456";
String[] FNN = FNNOrg.split(",");
int counter = FNN.length;
System.out.println("No of FNNs:"+counter);
int endcounter = counter - 1;
String json = "{" +
"\"status\": 200," +
"\"data\": {" +
"\"numberDetails\": [";
for (int i = 0; i < counter; i++) {
System.out.println("FNN values:"+FNN[i]);
json += "{ \"fullNationalNumber\": \""+FNN[i]+"\", \"fnnServiceabilityIndicator\": \"2\", \"reason\": \"3\", \"code\": \"4\" }";
if(i != endcounter) json += ",";
}
json += "]}}";
System.out.println("JSON = " + json);
}
}
I want to dynamically create JSON responses.