data_expand

Table of Contents

Prototype: data_expand(data_container)

Return type: data

Description: Transforms a data container to expand all variable references.

This function will take a data container and expand variable references once in all keys and values.

Any compound (arrays or maps) data structures will be expanded recursively, so for instance data in a map inside another map will be expanded.

This function is chiefly useful if you want to read data from an external source and it can contain variable references.

Arguments:

  • data_container: string, in the range: [a-zA-Z0-9_$(){}\[\].:]+

Example:

bundle agent main
{
  vars:
      "x" string => "the expanded x";
      "y" string => "the expanded y";

      "read" data => readjson("/tmp/expand.json", inf);
      "expanded" data => data_expand(read);

      "expanded_str" string => format("%S", expanded);

  reports:
      "$(this.bundle): the x and y references expanded to $(expanded_str)";
}

Output:

R: main: the x and y references expanded to {"the expanded x":"the expanded y"}

Notes:

History: Was introduced in version 3.7.0 (2015)

See also: readcsv(), readjson(), readyaml(), and data documentation.