Search code examples
jsonapigee

Embedding variables inside Apigee JSON payload


I want to return a JSON body inside an AssignMessage.

I found that if I write it as: <Payload> { "json":"json" } </Payload>

The { is interpreted as a variable. So I escaped it as <Payload> \{ "json":"json" } </Payload>

and the JSON payload comes out properly.

Now, I want to include a variable in the body, like message.queryparam.xxx. I can't use {} anymore since the initial { was escaped. How can I do this?


Solution

  • You can do it by defining the variable delimiters.

    <Payload contentType="application/json" variablePrefix="$" variableSuffix="%">
    {
        "Key": "$variableName%"
    }
    </Payload>