I am using Kong 3.3.0 in db-less mode using declarative yaml.
I'm trying to update the request body with a value present in the headers.
If I set a top-level JSON attribute it all works OK. When I try and update the value in a sub-object within the JSON then it fails; well, it sets the value but not exactly where I need it to be).
I am not sure if I am just specifying the JSON path incorrectly in the config or if this plugin doesn't actually support this functionality.
The relevant part of my kong.yaml when it works looks as follows:
- host: spring-template name: spring_template_service port: 12345 protocol: http routes: - name: spring_example paths: - /spring/example strip_path: false plugins: - name: request-transformer enabled: yes config: add: body: - newkey:newvalue replace: body: - newkey:newvalueWhen I pass in a request payload that looks as follows then the "newkey" attribute is either added if not present, or updated it it is present.
So for an empty input of:
{
}it correctly returns:
{ "newkey": "newvalue"
}I have confirmed this by inspecting the raw JSON that arrives at my Spring Boot service that Kong forwards the request onto.
As I say, I'm not sure how/if you can specify a sub object in the JSON but if I modify the relevant parts of the config above to be:
config: add: body: - newkey.subkey:newvalue replace: body: - newkey.subkey:newvaluethen in the JSON that is output from Kong I see this:
{ "newkey.subkey": "newvalue"
}whereas what I was hoping for was:
{ "newkey": { "subkey": "newvalue" }
}Does anyone know if the request-transformer plugin from Kong support this? The Kong documentation is pretty sparse and only covers very simple use-cases.
I have tried different patterns of config but none of them seem to give me what I need.
The only other option open is to write my own plugin to do what I need.
Related questions 0 Kong request-transformer: Replace URI attribute with header value 0 Kong Gateway replace response status code 0 How to do conditional request termination with kong api-gateway? Related questions 0 Kong request-transformer: Replace URI attribute with header value 0 Kong Gateway replace response status code 0 How to do conditional request termination with kong api-gateway? 2 Kong rate limit plugin to multiple services 0 Kong dbless/kong-oidc - Is it possible to use kong-oidc plugin dbless? 0 Custom Plugin Configuration in KONG Kubernetes Using Declarative Configuration 1 kong request transformer invoke multiple microservice APIs 0 Kong response-transformer-advanced plugin Load 5 more related questions Show fewer related questions Reset to default