Response transformer in JSON array


#1

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.


#2

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?


#3

Thank you for your reply @bungle!

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


#4

A year after. Has this been implemented?

Thanks

Nic