JSON response filter - HTTP

This filter allows you to intercept JSON responses as they come from the server, and modify them if needed before they get forwarded to the client.

You must ensure that all the responses for this filter contain JSON text, otherwise an exception will be thrown when the content is parsed.

This is usually done either by specifying a URL that is known to respond with JSON, or by specifying an appropriate Content-type header.


URL pattern

Optional. Specifies for which request URL(s) the filter should be executed. This does not include the protocol, host and port number. If specified, it can be either:

  • a URL as a string for which this filter should get executed. For instance: /rest/state

  • a regular expression (starting with regex: ) that matches the URL. For instance: regex:/rest/state/[0-9]+

Examples: /rest/customers regex:/rest/customers/[0-9]+


Optional. If specified, the request's HTTP method (e.g. GET, POST, PUT, etc...) for which this filter should get executed. If not specified, all methods will match.

Client IPs

Optional. If specified, a comma-separated (or line break separated) list of IP4 or IP6 addresses or regular expressions for IP addresses. If specified, only requests from matching IP addresses will cause the execution of the filter.

Examples:, regex:12.34.56.\d{1,3} 2600:1701:6440:69f0:57:9a9c:d277:8321

Header patterns

Optional. If specified, a newline-separated list of response header specifications which must match. The name of the header is a simple string, followed by a colon, and a regular expression for the header value. For instance:

Content-type: ((application/json)|(text/json))

If more than one pattern is specified (separated by line breaks), then the filter will be executed if at least one of the patterns matches at least one header in the response.

Examples: Content-type: application/json Accept-encoding: regex:g?zip.*

Status code patterns

Optional. If specified, this filter will be invoked only if the response's HTTP status code matches one of the patterns specified. For instance:

  • 200

  • 200, 201, 202

  • regex:20\d

JSON path

Optional. A JSON Path expression. If specified, this filter will be invoked only if the body of the response contains at least one object that matches this expression. If this is specified, the result of this JSON path will be available to the filter in the variable context.jsonPathResult.


In addition to the usual variables, this filter also defines the following variables:

  • context.jsonPathResult : if the JSON path parameter is set, then the result of that path will be available in this variable.

  • context.jsonHolder : a JSON holder object providing access to the JSON payload


Change the encoding of the payload

let payload = context.response.payloadString;

context.response.setPayloadString(payload, "UTF-16");

context.response.setResponseHeader("Content-type", "application/json; charset=utf-16");