Tyk v2.2 Documentation Components

  1. Home
  2. Tyk v2.2 Documentation Components
  3. Request body: JSON data

Request body: JSON data

Tyk will unmarshal the data into a data structure, and then make that data available to the template in dot-notation. Here is an example to illustrate.

JSON

Assume your inbound date structure is as follows:

{
    "value1": "value-1",
    "value2": "value-2",
    "value_list": [
        "one",
        "two",
        "three"
    ]
}

Template

You could use a golang template that looks like this to transform it into a different format:

{
    "value1": "{{.value2}}",
    "value2": "{{.value1}}",
    "transformed_list": [
        {{range $index, $element := .value_list}}
            {{if $index}}
            , "{{$element}}"
            {{else}}
                 "{{$element}}"
            {{end}}
        {{end}}
    ]
}

Output

This example would produce the following output:

{
    "value1": "value-1",
    "value2": "value-2",
    "transformed_list": [
        "one",
        "two",
        "three"
    ]
}