Is there in any way to get request/response in single line json instead of multiline.

We have a requirement where we need pass logs to splunk in single line json. Is there any message template available in message logging policy where we can convert multi line json into single line?

E.g.

{

"id": 123,

"name": "user",

"company" : "MyCompany",

"tenure": 5

}

Single line: {"id":123, "name":"user", "company: "MyCompany", "tenure": 5}

0 4 2,825
4 REPLIES 4

Not applicable

You can use below cod ein python script on the response.

str1=str.replaceAll("[\r\n]+"," ");

Thanks priyadarshi for your answer. But I don't want to use any custom code, as we will also have multiple service callout request response, which we need to log via message logging policy. And adding custom code for each callout request/response may impact the performance.

If performance is the concern then you cn use java calout.

The simplest non-Java-callout solution is a JavaScript Policy one-liner:

context.setVariable('response.content',JSON.stringify(JSON.parse(context.getVariable('response.content'))))

It takes 8 ms to process 113K json datagram.

3 ms for 14K json.

What's your performance expectation?