Section – Rewrite Response Body (JSON only)
Airlock Gateway Airlock Microgateway provides a JSON content rewriter for values in JSON documents.
Recommended use:
- Use JSONPath (XPath for JSON) and content pattern (which work as regular expressions) to rewrite any URLs of the JSON content.
Content pattern as rewrite variables
Rewrite rules may contain rewrite variables for URLs. This can be achieved by using a content pattern, i.e., (?<URL>)
.
The type specifier ?<URL> right after the opening parenthesis indicates a URL. If URL encryption is enabled, this URL will also be encrypted.
Examples:
JSONPath | Content Pattern | Replace |
---|---|---|
$..url | (?<URL>.*) | $1 |
$..url | ^(https?://)%BACKENDHOST%/%BACKENDPATH%(/.*)?$ | $1%ENTRYHOST%/%ENTRYPATH%$2 |
$.data.services[:].name | path | location |
JSON Path example
To define which field to rewrite, JSON Path syntax is used.
JSON Document:
Example
{ "data": { "services": [ { "name": "path1", "url": "http://backend-server/path1" }, { "name": "path2", "url": "http://backend-server/path2" } ] } }
JSON Paths:
Example
* $.data.services[0].name selects the value "path1" * $.*.services[0].name selects the value "path1" * $.data.services[:].name selects the values ["path1", "path2"] * $..url selects all URLs