Response transformer in JSON array

Hi, I was wondering if anybody can help me?

I am trying to run a response transformer in a golang api. For a better view, I receive the following when I trigger the sample below:

Triggered:
curl -i -X GET --url http://localhost:8000/ --header “Host: example”

Results:
[
{
“title”:“Power of Habit”,
“author”:“Charles Duhigg”,
“isbn”:“123456789”
},
{
“title”:“IT”,
“author”:“Stephen King”,
“isbn”:“1234567898”
}
]

I have added a response transformer as below:
curl -X POST --url http://localhost:8001/apis/example-api/plugins --data “name=response-transformer” --data “config.remove.json=isbn”

but somehow I am still getting the same results. the isbn is still present. I’m I missing something?

Thank you in advance.

The reason that this doesn’t work is that the current transformations don’t work with JSON arrays AFAIK:

for _, name in iter(conf.remove.json) do
  json_body[name] = nil
end

It is a good idea though. E.g. add some detection of arrays here:

And if it is an array response, then do the remove in each object in array. Would you like to try send a pull-request for that?

Thank you for your reply @bungle!

I now understand the problem. I think the array checking would be useful.

A year after. Has this been implemented?

Thanks

Nic

After all of these comments and a year after, I have the same problem, but here is not about array as I could see in other github questions. In my case is about a simple JSON object. Take a look at the image below:

As you can see, I tried some different combinations for the items in “remove json”, but I also have the same result. Take a look at the image below:

See? This plugin doesn’t work as expected for remove and isn’t only for remove, I tried to use “add” and it didn’t work too.

This Kong version which I’m using:
image

Someone else can help to solve this problem?

1 Like

Try curl command instead of Postman, I think maybe cached on Postman