cancel
Showing results for 
Search instead for 
Did you mean: 

How to read the Json data direct in Content modifier in HCI

Former Member

HI

I am bit curious about how we can read input JSON data directly like we use XPATH to refrer XML tags

I want to set some custom properties and headers in Content modifier and send the same data i.e. JSON to HTTP request and reply.

Regards

GK

saitrinadhreddy
Discoverer
0 Kudos

source from chatgpt

content Modifier in SAP CPI is a powerful tool that allows you to modify the content of a message, which can include JSON files.

In fact, there are several expressions in Content Modifier that are specifically designed for manipulating JSON files, such as ${json('<JSONPath expression>')}, which extracts the value of a JSON element using a JSONPath expression, and ${json.set('<JSONPath expression>', '<value>')}, which sets the value of a JSON element using a JSONPath expression.

Using these expressions, you can easily manipulate the content of a JSON message in Content Modifier. For example, you could extract a specific value from a JSON object using ${json('$.customer.name')} and then store that value in a message property using ${property.name}. You could also modify the value of a JSON object using ${json.set('$.customer.email', 'newemail@example.com')}, which would set the email address of the customer object to a new value.

Accepted Solutions (1)

Accepted Solutions (1)

Sriprasadsbhat
Active Contributor

Hello Golu,

It's not possible to set the content of input json message to properties in content modifier.

You can have a Script and parse the incoming messages and set as properties or headers.

To know more about how to parse JSON you can search for jsonslurper in groovy it will ease handling JSON messages.

Regards,

Sriprasad Shivaram Bhat

dineshhome1361_7
Participant
0 Kudos

Hi SriPrasad,

Does this indicate content Modifier only accepts if the input is XML? Please clarify

Thanks,

Dinesh

philippeaddor
Active Participant
0 Kudos

Yes, it can only access the payload for reading if it's XML, unfortunately. A pitty that JSON parsing is not built-in and we need to use a script every time. Please vote for the corresponding feature request with SAP: https://influence.sap.com/sap/ino/#/idea/264381/?section=sectionDetails

Answers (1)

Answers (1)

Christopher
Participant
0 Kudos

No, the ContentModifier accepts "everything", but to use functions like XPath, the body must be XML