Remove field from JSON object

Hi Team,

I have a request payload( mentioned below), from which i need to remove customField (type string) and set request.content.

Upon trying multiple functions, methods of Java script available from different sources i am receiving [object Object] as output in most of the cases. But i need same payload which is in request.content,  just by removing customField. Please suggest a java script or an alternate( No Assign Message please , it will loose integrity )

Input Payload:

{
"requesteddata": "HELLO",
"tpetoyp": "Kalis",
"sndrf": "8y89g94-f894-f489",
"trfmt": 9876,
"trfrcrt": "BHGYU",
"customField": "some $%^& value"
}

Expected Output:

{
"requesteddata": "HELLO",
"tpetoyp": "Kalis",
"sndrf": "8y89g94-f894-f489",
"trfmt": 9876,
"trfrcrt": "BHGYU"
}

 

Thanks

 

 

Solved Solved
0 1 640
1 ACCEPTED SOLUTION

Try below..

try {
  var req = JSON.parse(context.getVariable("request.content"));
  delete req.customField;
  context.setVariable("request.content", JSON.stringify(req));
} catch (error) {
  context.setVariable("debug", error);
  throw error;
}

View solution in original post

1 REPLY 1

Try below..

try {
  var req = JSON.parse(context.getVariable("request.content"));
  delete req.customField;
  context.setVariable("request.content", JSON.stringify(req));
} catch (error) {
  context.setVariable("debug", error);
  throw error;
}