2025 Feb 04 8:44 AM - edited 2025 Feb 04 8:55 AM
Hello, I'm still new to groovy scripting and I would like to achieve the following output.
Example
Input:
{
"Book": {
"Title": {
"@nil": "true"
},
"Author": {
"@nil": "true"
},
"year": "1960",
"isbn": "9780061120084"
}
}
Output:
{
"Book": {
"Title":null,
"Author": null,
"year": "1960",
"isbn": "9780061120084"
}
}
I need to change all the fields that has value = {"@nil": "true"} to null. How can I achieve this via groovy script? would really appreciate your help on this. Thank you!
Request clarification before answering.
Hi @ZTK196
Work with JSON in Groovy is easy with the classes:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @robertot4s,
I used this script instead since they have common values.
import com.sap.gateway.ip.core.customdev.util.Message;
def Message processData(Message message) {
def body = message.getBody(java.lang.String);
body = body.replaceAll(/\{\s*"@nil":\s*"true"\s*\}/, 'null');
message.setBody(body);
// Set Content-Type
message.setHeader("Content-Type","application/json");
return message;
}Still, Thank for your inputs, much appreciated.
| User | Count |
|---|---|
| 17 | |
| 7 | |
| 6 | |
| 6 | |
| 4 | |
| 4 | |
| 4 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.