TemplateJSON

This formatter unmarshals the given data as JSON and applies the results to the given go template. The JSON data will be replaced with the rendered template result. The template language is described in the go documentation: https://golang.org/pkg/text/template/#hdr-Actions

Parameters

Template

Defines the go template to execute with the received JSON data. If the template cannot be parsed or the JSON payload cannot be unmarshaled, the incoming JSON data is preserved. By default this parameter is set to “”.

Parameters (from core.SimpleFormatter)

ApplyTo

This value chooses the part of the message the formatting should be applied to. Use “” to target the message payload; other values specify the name of a metadata field to target. By default this parameter is set to “”.

SkipIfEmpty

When set to true, this formatter will not be applied to data that is empty or - in case of metadata - not existing. By default this parameter is set to false

Examples

This example extracts the fields “Name” and “Surname” from a JSON encoded payload and writes them both back as a plain text result.

exampleConsumer:
  Type: consumer.Console
  Streams: "*"
  Modulators:
    - format.TemplateJSON:
      Template: "{{.Name}} {{.Surname}}"