Functions can be placed anywhere and allow you to extract information from your environment, generate values, or access data from the underlying message being mapped:
Returns the index of the mapped message within a batch. This is useful for applying maps only on certain messages of a batch:
Returns the size of the message batch.
Returns the full raw contents of the mapping target message as a byte array. When mapping to a JSON field the value should be encoded using the method
encode, or cast to a string directly using the method
string, otherwise it will be base64 encoded by default.
count function is a counter starting at 1 which increments after each time it is called. Count takes an argument which is an identifier for the counter, allowing you to specify multiple unique counters in your configuration.
This is a special function indicating that the mapping target should be deleted. For example, it can be used to remove elements of an array within
If an error has occurred during the processing of a message this function returns the reported cause of the error. For more information about error handling patterns read here.
Resolves to the hostname of the machine running Benthos.
Returns the value of a field within a JSON message located by a dot path argument. This function always targets the entire source JSON document regardless of the mapping context.
The path parameter is optional and if omitted the entire JSON payload is returned.
Returns the value of a metadata key from a message identified by a key. Values are extracted from the referenced input message and therefore do NOT reflect changes made from within the map.
The parameter is optional and if omitted the entire metadata contents are returned as a JSON object.
Generates a non-negative pseudo-random 64-bit integer. An optional integer argument can be provided in order to seed the random number generator.
Prints the current time in a custom format specified by the argument. The format is defined by showing how the reference time, defined to be
Mon Jan 2 15:04:05 -0700 MST 2006 would be displayed if it were the value.
A fractional second is represented by adding a period and zeros to the end of the seconds section of layout string, as in
15:04:05.000 to format a time stamp with millisecond precision.
Resolves to the current unix timestamp in seconds. You can add fractional precision up to the nanosecond by specifying the precision as an argument, e.g.
timestamp_unix(3) for millisecond precision.
Resolves to the current unix timestamp in nanoseconds.
The equivalent of
timestamp except the time is printed as UTC instead of the local timezone.
Generates a new RFC-4122 UUID each time it is invoked and prints a string representation.