# Not able to modify response in Kong open source

**URL:** <https://discuss.konghq.com/t/not-able-to-modify-response-in-kong-open-source/12949>\
**Category:** Questions\
**Created:** [August 22, 2024, 11:54am UTC](https://discuss.konghq.com/t/not-able-to-modify-response-in-kong-open-source/12949 "2024-08-22T11:54:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitiraj\_pachkale](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/nitiraj_pachkale/32/4620_2.png) [@nitiraj\_pachkale](https://discuss.konghq.com/u/nitiraj_pachkale)\
**Post date:** [August 22, 2024, 11:54am UTC](https://discuss.konghq.com/t/not-able-to-modify-response-in-kong-open-source/12949/1 "2024-08-22T11:54:13Z")

</div>

Hi There,

I have a usecase where I need to modify the upstream service response before sending it back to the client application. I am trying to use Post Function to edit the response. But facing challenges to parse and build new JSON.

Can you please help me to achieve this in Kong open source docker version?

Thanks,  
Nitiraj

---

<div class="post-metadata">

**Author:** ![rick](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/rick/32/4446_2.png) [@rick](https://discuss.konghq.com/u/rick)\
**Post date:** [August 23, 2024, 1:20am UTC](https://discuss.konghq.com/t/not-able-to-modify-response-in-kong-open-source/12949/2 "2024-08-23T01:20:28Z")

</div>

@nitiraj_pachkale Does the Request Transformer plugin work for your case? If not, please provide more details in your question so we can try and assist with the issue. Include any example configuration and steps to reproduce. Thanks

---

<div class="post-metadata">

**Author:** ![nitiraj\_pachkale](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/nitiraj_pachkale/32/4620_2.png) [@nitiraj\_pachkale](https://discuss.konghq.com/u/nitiraj_pachkale)\
**Post date:** [August 23, 2024, 4:57am UTC](https://discuss.konghq.com/t/not-able-to-modify-response-in-kong-open-source/12949/3 "2024-08-23T04:57:35Z")

</div>

Hi @rick,

Thanks for your reply.

Yes, request trasformer is working fine with both “Request Transformer” plugin and “Pre Function” plugin with Lua Script. I am able to send modified request to upsteam service. But facing problem while I am trying to modify response returned by upstream service.

I am trying to use Lua Script in response flow. Please find below the same -

_local cjson = require “cjson”_  
_local body = kong.response.get\_raw\_body()_  
_local json\_body = cjson.decode(body)_  
_local json\_obj = json\_body.json_  
_local new\_json\_body = cjson.encode(json\_obj)_  
_kong.response.set\_raw\_body(new\_json\_body)_

Basically there is a key with name “json” in response body. I want to extract that and set it as new response body.

I am using Post Function Plugin with Lua script. Phase - body\_filter

Please help me to undestand how we can achieve this using Lua Scritp.

Thanks,  
Nitiraj

---

<div class="post-metadata">

**Author:** ![rick](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/rick/32/4446_2.png) [@rick](https://discuss.konghq.com/u/rick)\
**Post date:** [August 27, 2024, 1:46pm UTC](https://discuss.konghq.com/t/not-able-to-modify-response-in-kong-open-source/12949/4 "2024-08-27T13:46:29Z")

</div>

@nitiraj_pachkale Can you please provide the current behavior or error you observe with your existing code?

---

<div class="post-metadata">

**Author:** ![nitiraj\_pachkale](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/nitiraj_pachkale/32/4620_2.png) [@nitiraj\_pachkale](https://discuss.konghq.com/u/nitiraj_pachkale)\
**Post date:** [September 3, 2024, 6:01am UTC](https://discuss.konghq.com/t/not-able-to-modify-response-in-kong-open-source/12949/5 "2024-09-03T06:01:39Z")

</div>

This issue is resolved. I built custom plugin using lua to modify response.

Thanks,  
Nitiraj
