ExtractJSON

This formatter extracts a specific value from a JSON payload and writes it back as a new payload or as a metadata field.

Parameters

Field

Defines the JSON key to extract. If the field does not exist an empty string is returned. Field paths can be defined in a format accepted by tgo.MarshalMap.Path. By default this parameter is set to “”.

TrimValues (default: true)

Enables trimming of whitespaces at the beginning and end of the extracted value. By default this parameter is set to true.

Precision (default: -1)

Defines the number of decimal places to use when converting Numbers into strings. If this parameter is set to -1 the shortest possible number of decimal places will be used. By default this parameter is set to -1.

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

ExampleConsumer:
  Type: consumer.Console
  Streams: console
  Modulators:
    - formatter.ExtractJSON
      Field: host
      ApplyTo: host