Kong Gateway - Updating request JSON using request-transformer plugin

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:newvalue

When 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:newvalue

then 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

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like