validjson

Table of Contents

Prototype: validjson(string)

Return type: boolean

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

Arguments:

  • string: string - String to validate as JSON - in the range: .*

Example:

Run:

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

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

Output:

R: This JSON string is valid!

See also: readjson(), validdata()

History: Was introduced in 3.16.0.