I need a way to remove leading square brackets from a JSON file. I'm doing it in SAP cloud platform integration (CPI). Currently I was thinking of using groovy but can't seem to find a way to do it. Here's the JSON example:
[{
"salesOrderNumber": "1234567",
"orderStatus": "Complete",
"customerPONumber": "7654321",
"soldToID": "ABC",
"soldToName": "CBA"
}
]
Thank you in advance.
The code I used was for getting just one element, but I need to get multiple in case there are many.
def Message processData(Message message) {
def body = message.getBody(String.class);
def jsonParser = new JsonSlurper();
def jsonObject = jsonParser.parseText(body);
def json = JsonOutput.toJson(jsonObject[0]);
println(json);
message.setBody(json);
return message;
}