You can use the json-to-json
policy to apply a transformation (or mapping) on the request and/or response and/or
message content.
This policy is based on the JOLT library.
In APIM, you need to provide the JOLT specification in the policy configuration.
Note
|
You can use APIM EL in the JOLT specification. |
At request/response level, the policy will do nothing if the processed request/response does not contain JSON. This
policy checks the Content-Type
header before applying any transformation.
At message level, the policy will do nothing if the processed message has no content. It means that the message will be re-emitted as is.
You can configure the policy with the following options:
Property | Required | Description | Type | Default |
---|---|---|---|---|
scope |
only for v3 engine |
The execution scope ( |
string |
|
specification |
X |
The JOLT specification to apply on a given content. Can contains EL. |
string |
|
overrideContentType |
Override the Content-Type to |
string |
|
Example configuration:
{
"json-to-json": {
"scope": "REQUEST",
"specification": "[{ \"operation\": \"shift\", \"spec\": { \"_id\": \"id\", \"*\": { \"$\": \"&1\" } } }, { \"operation\": \"remove\", \"spec\": { \"__v\": \"\" } }]"
}
}
For this input:
{
"_id": "57762dc6ab7d620000000001",
"name": "name",
"__v": 0
}
And this JOLT specification:
[
{
"operation": "shift",
"spec": {
"_id": "id",
"*": {
"$": "&1"
}
}
},
{
"operation": "remove",
"spec": {
"__v": ""
}
}
]
The output is as follows:
{
"id": "57762dc6ab7d620000000001",
"name": "name"
}