template Action
The <template>
action is the primary tool for generating JSON data in FLAT's Template Language.
Syntax
in
: Location of input dataEither a file (e.g.
in="conf.json"
) or a variable (in="$body"
). The input sets the template's initial context ({{.}}
). It may be a JSON or XML document.in=""
signals that no input data is used.The context can be changed within the template with
{{with …}}
.Default:
fit://request/content
out
: Location of output dataWhere the generated JSON should be stored.
This can be a variable. Variables will hold the typed result, such as a JSON object or e.g. a boolean value.
Default:
fit://request/content
src
: Location of the template fileThe template definition can be stored in a separate file. The file path is resolved relatively to the flow file.
There is no obligatory file extension. However, we recommend
tmpl
ortpl
.check
: Check outputThe generated JSON will be parsed and checked. If the template has produced an invalid JSON string, an error will be logged.
The generated text will still be written to the configured
out
location. In that case, ifout
is a variable, the output is not typed.Checking can be disabled with
check="false"
.Default:
true
Examples
Accessing JSON data received from client's
The pre-defined variable $body
holds the HTTP body of incoming POST
requests.
Request with curl
:
Output:
Accessing JSON data loaded from upstream servers
In this example, we pass the client's POST
body to httpbin.org to have it reflected back.
Request with curl
:
Output:
Using a template file
The file path modifyResponse.tmpl
is resolved relatively to the flow file.
modifyResponse.tmpl
:
Last updated