cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to add root nodes in json payload using groovy script in sap cpi

meerhyderali
Explorer
0 Kudos

Hi Team,

I have the below payload in Json format and i require to add the root node with data.

Current Json Payload

{

"attributes": {

"type": "TEST",

"url": "www"

},

"Id": "XYZ",

"IsDeleted": No,

}

Required Json Payload.

{ "data": {

"attributes": {

"type": "TEST",

"url": "www"

},

"Id": "XYZ",

"IsDeleted": No,

}

}

When i am using the below login in groovy script, its failing with error.

def actPayload = [data: body]; messageLog.addAttachmentAsString('03-REQUEST-json', JsonOutput.prettyPrint(actPayload), 'text/plain');

Can anyone help in groovy script on this issue.

Regards,

Ali

View Entire Topic
raihan_siddiqui
Explorer
0 Kudos

Hi Hyder Ali,

Please use the following code:

import groovy.json.*;

def Message jsonCreate (Message message)

{

def builder = new JsonBuilder();

builder{

data{

attributes{

type("test")

url("www")

}

id("1234")

isDeleted("No")

}

}

message.setBody(builder.toPrettyString())

return message;

}

Thanks,

Regards,

Raihan