Changing a JSON payload "on the fly"

On one of the proxy of my org, I have the (temporary) need to change a value on the payload.

In the past, I successfully used the "Assign Message" policy for changing some headers or a HTTP verb. It was pretty simple.

Now I have a call with a JSON payload on it. There is a value I need to intercept and change. And it does not seems straightforward as it was for headers or verb.

I will receive the following payload on the request (sorry for the *** but I need some privacy) :

{"deviceSerialNumber": "****","deviceDataMatrix": "null","makerName": "****","makerCode": "****","countryOfService": "ES","assetTypeCode": "***","assetMakerName": "***","assetModelDescription": "***","assetBodyTypeCode": "SPORT","assetFrameNumber": "****","assetFuelType": "Petrol","assetEngineSize": null,"assetPrimaryColor": "BLACK","assetRegistrationDate": null,"assetRegistrationNumber": null,"assetDevicePosition": null,"assetSensorPosition": null,"assetCoveredDistance": null}

I need to change these two guys:

from "assetBodyTypeCode": "SPORT" to "assetBodyTypeCode": "44"

from ,"assetFuelType": "Petrol" to ,"assetFuelType": "PETROL"

Can you help in writing a sensible "Assign Message" policy?

0 1 865
1 REPLY 1

I would use a javascript extension policy to do this instead. It will be cleaner and less prone to problems, IMO. You just parse the payload into a variable and then manipulate elements directly, then reassign the payload.