validdata

Table of Contents

Prototype: validdata(data_container, type)

Return type: boolean

Description: Validates a JSON container from data_container and returns true if the contents are valid JSON.

This function is intended to be expanded with functionality for validating CSV and YAML files eventually, mirroring readdata(). If type is JSON, it behaves the same as validjson().

Arguments:

  • data_container: string, in the range: .*
  • type: one of
    • JSON

Example:

Run:

bundle agent main
{
  vars:
    "json_string" string => '{"test": [1, 2, 3]}';

  reports:
    "This JSON string is valid!"
      if => validdata("$(json_string)", "JSON");
    "This JSON string is not valid."
      unless => validdata("$(json_string)", "JSON");
}

Output:

R: This JSON string is valid!

See also: readdata(), validjson()

History: Was introduced in 3.16.0.