Response Transformer Advanced

Related Documentation
Made by
Kong Inc.
Supported Gateway Topologies
hybrid db-less traditional
Supported Konnect Deployments
hybrid cloud-gateways serverless
Compatible Protocols
grpc grpcs http https

This plugin allows you to transform the response sent by the upstream server on the fly before returning it to the client.

The Response Transformer Advanced plugin provides features that aren’t available in the Response Transformer plugin, including:

  • When transforming a JSON payload, transformations are applied to nested JSON objects and arrays. This can be turned enabled and disabled using the config.dots_in_keys configuration parameter. See Arrays and nested objects for more information.
  • Transformations can be restricted to responses with specific status codes using various config.*.if_status configuration parameters.
  • JSON body contents can be restricted to a set of allowed properties with config.allow.json.
  • The entire response body can be replaced using config.replace.body.
  • Arbitrary transformation functions written in Lua can be applied.
  • The plugin will decompress and recompress Gzip-compressed payloads when the Content-Encoding header is gzip.

Notes:

  • Transformations on the response body can cause changes in performance. To parse and modify a JSON body, the plugin needs to retain it in memory, which might cause pressure on the worker’s Lua VM when dealing with large bodies (several MB). Because of Nginx’s internals, the Content-Length header will not be set when transforming a response body.
  • If the value contains a , then the comma separated format for lists cannot be used. Array notation must be used instead.

Order of execution

The plugin performs the transformations in the following order:

  1. Remove
  2. Rename
  3. Replace
  4. Add
  5. Append

Arrays and nested objects

The plugin allows navigating complex JSON objects (arrays and nested objects) when config.dots_in_keys is set to false (the default is true):

  • array[*]: Loops through all elements of the array.
  • array[N]: Navigates to the nth element of the array (the index of the first element is 1).
  • top.sub: Navigates to the sub property of the top object.

These can be combined. For example, config.remove.json: customers[*].info.phone removes all phone properties from inside the info object of all entries in the customers array.

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!