cancel
Showing results for 
Search instead for 
Did you mean: 

Separate json payload from the notification

jayesh040583
Explorer
0 Kudos
519

Hi All,

Could you please suggest how I can separate the JSON payload which is a part of the notification received from the sender system?

Below is the string received from the sender system. The JSON payload start after resourceObject=

ThirdPartyEventDto_V1{eventType='serviceCall.created', eventTypeVersion='1.0', cloudEventsVersion='0.1', source='/api/v1/streaming', eventID='dc62e53e-4f7d-4fe0-a0d0-139b86c371c6', eventTime='2021-01-06T11:01:48.836Z', contentType='application/json', extensions={traceId=b3:68192612759c383f-8b3f87961b3be7fd-1-2cec66e9995b0ef2}, data={resourceId='364EDA385C5E4C1D8B2ABD31EEE9565E', resourceDtoVersion='ServiceCall.24', resourceObject={"leader":null,"subject":"Test Dec 6 03","chargeableEfforts":false,"project":null,"owners":null,"objectGroup":null,"resolution":null,"syncObjectKPIs":null,"inactive":false,"partOfRecurrenceSeries":null,"contact":null,"problemTypeName":"Out of Fuel","originCode":"-2","id":"364EDA385C5E4C1D8B2ABD31EEE9565E","problemTypeCode":"M1","changelog":null,"endDateTime":"2021-01-06T13:00:05Z","priority":"MEDIUM","branches":null,"salesOrder":null,"dueDateTime":"2021-01-06T18:29:59Z","salesQuotation":null,"udfMetaGroups":null,"orderReference":null,"responsibles":["48ADC2AEA2F2451C83BC28FE172339AF"],"syncStatus":"IN_CLOUD","statusCode":"-2","code":"141","businessPartner":"AD5A7474B098420888168781F1537448","projectPhase":null,"technicians":[],"typeName":"Repair","chargeableMileages":false,"chargeableMaterials":false,"statusName":"WIP","orderDateTime":null,"chargeableExpenses":false,"lastChanged":1609930887620,"serviceContract":null,"createPerson":"48ADC2AEA2F2451C83BC28FE172339AF","externalId":null,"groups":null,"team":null,"typeCode":"-1","createDateTime":"2021-01-06T11:01:18Z","equipments":["1CB51E7F38DB4CA7BA15A82212AA868C"],"startDateTime":"2021-01-06T11:00:05Z","location":null,"udfValues":[{"meta":"F1D0BA61CFC14B4785761E29AAA8B7D3","value":"Sispal Vihar"},{"meta":"61BFE4298B9944F9BAA818BFC989E939","value":"3101"},{"meta":"8C38827D58104B35BC2AF236E43A05B1","value":"Gurugram"},{"meta":"956490EDC351420681798A3EF0B495F9","value":"122018"},{"meta":"6E87A0EE74324621A029EB75D7B1D850","value":"HR"},{"meta":"B1744F9F3E4A4A428EAD5D871B1FE75F","value":"IN"},{"meta":"FC26130E84A64BE1B3810E8A057A62D0","value":"TY"},{"meta":"25A47FEF11734329BF7AB5B1CC3FEE62","value":"true"}],"lastChangedBy":null,"incident":null,"remarks":null,"originName":"Telephone"}}}


Regards,

Jayesh

Accepted Solutions (1)

Accepted Solutions (1)

MortenWittrock
Active Contributor

Hi Jayesh

You need to do a little bit of Groovy string manipulation, to extract the JSON object, which can then be converted to XML, mapped and so on.

Add the following Groovy script before the JSON to XML conversion step:

import com.sap.gateway.ip.core.customdev.util.Message

def Message processData(Message message) {
    def body = message.getBody(String)
    // Get the index of the start of the JSON object.
    def objIndex = body.indexOf('{', body.indexOf('resourceObject='))
    // Extract the JSON object.
    message.setBody(body[objIndex..-3])
    // All done.
    message
}

Please note that the code assumes exactly the format you copypasted above. If that format changes, you will have to update the code accordingly.

Regards,

Morten

jayesh040583
Explorer

Hi Morten,

Thank you very much.

The script worked perfectly well. It solved my problem.

Regards,

Jayesh.

Answers (2)

Answers (2)

jayesh040583
Explorer
0 Kudos

Thank you Sriprasad.

Yes, the JSON is not proper. The bold part is the actual JSON but it is attached in the string. I am trying to separate it so that I can convert it into xml and then utilize it in mapping

ThirdPartyEventDto_V1{eventType='serviceCall.created', eventTypeVersion='1.0', cloudEventsVersion='0.1', source='/api/v1/streaming', eventID='dc62e53e-4f7d-4fe0-a0d0-139b86c371c6', eventTime='2021-01-06T11:01:48.836Z', contentType='application/json', extensions={traceId=b3:68192612759c383f-8b3f87961b3be7fd-1-2cec66e9995b0ef2}, data={resourceId='364EDA385C5E4C1D8B2ABD31EEE9565E', resourceDtoVersion='ServiceCall.24', resourceObject=


{"leader":null,"subject":"Test Dec 6 03","chargeableEfforts":false,"project":null,"owners":null,"objectGroup":null,"resolution":null,"syncObjectKPIs":null,"inactive":false,"partOfRecurrenceSeries":null,"contact":null,"problemTypeName":"Out of Fuel","originCode":"-2","id":"364EDA385C5E4C1D8B2ABD31EEE9565E","problemTypeCode":"M1","changelog":null,"endDateTime":"2021-01-06T13:00:05Z","priority":"MEDIUM","branches":null,"salesOrder":null,"dueDateTime":"2021-01-06T18:29:59Z","salesQuotation":null,"udfMetaGroups":null,"orderReference":null,"responsibles":["48ADC2AEA2F2451C83BC28FE172339AF"],"syncStatus":"IN_CLOUD","statusCode":"-2","code":"141","businessPartner":"AD5A7474B098420888168781F1537448","projectPhase":null,"technicians":[],"typeName":"Repair","chargeableMileages":false,"chargeableMaterials":false,"statusName":"WIP","orderDateTime":null,"chargeableExpenses":false,"lastChanged":1609930887620,"serviceContract":null,"createPerson":"48ADC2AEA2F2451C83BC28FE172339AF","externalId":null,"groups":null,"team":null,"typeCode":"-1","createDateTime":"2021-01-06T11:01:18Z","equipments":["1CB51E7F38DB4CA7BA15A82212AA868C"],"startDateTime":"2021-01-06T11:00:05Z","location":null,"udfValues":[{"meta":"F1D0BA61CFC14B4785761E29AAA8B7D3","value":"Sispal Vihar"},{"meta":"61BFE4298B9944F9BAA818BFC989E939","value":"3101"},{"meta":"8C38827D58104B35BC2AF236E43A05B1","value":"Gurugram"},{"meta":"956490EDC351420681798A3EF0B495F9","value":"122018"},{"meta":"6E87A0EE74324621A029EB75D7B1D850","value":"HR"},{"meta":"B1744F9F3E4A4A428EAD5D871B1FE75F","value":"IN"},{"meta":"FC26130E84A64BE1B3810E8A057A62D0","value":"TY"},{"meta":"25A47FEF11734329BF7AB5B1CC3FEE62","value":"true"}],"lastChangedBy":null,"incident":null,"remarks":null,"originName":"Telephone"}}}.

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Jayesh,

It doesn't seems to be valid JSON. Please share proper correct JSON so that someone can suggest solution.

Regards,

Sriprasad Shivaram Bhat