Json formatting to remove \n and \ before and after json attribute in apigee proxy response

This is small snippet :

{
“content”: “[\n {\n "gmb_code": INDINDIND",\n "reputation_name": "Some Hospitalname"]”
}

But I need it to be without \ and \n like below

{

“gmb_code” : “INDINDIND”,

“reputation_name”: “Some Hospitalname”
}

Suppose you have a context variable called “my-response-message” of type Message. A Message is a complex type of variable in Apigee. It represents an entire HTTP message, including headers, payload, and… if it is a request, a verb and url, and maybe query params. If it is a response, the message will hold a status code string. Suppose further that the content of that message is:

{
"content": "[\n {\n \"gmb_code\": INDINDIND\",\n \"reputation_name\": \"Some Hospitalname\"]"
}

That is proper JSON. We can say it is a JSON object with a single property, named “content” and the value of that property is a string. The string itself appears to be an escaped form of… almost JSON. Maybe it is supposed to be JSON and there was a cut/paste error. Let me assume that to be the case.

If you wanted to manipulate or read the inner thing in a JS callout, then you would do this:

// parse the payload into a JS object:
var c = JSON.parse(context.getVariable('my-response-message.content'));
// get one field in that object
var innerJSON = c.content;
// parse THAT as JSON
var object = JSON.parse(innerJSON); 
// at this point:
// object[0].gmb_code = "INDINDIND"
1 Like

Javascript formatting I’m able to do, but problem I understood now is because of AssignMessage policy.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> Assign Message-ADSI {storage.file.retrieved}

We need to extract content from here. Please suggest if possible.

We need to extract content from here.

I don’t know what you mean, sorry. From here? I am unclear as to the problem you’re trying to solve.