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
- Data to validate - in the range:.*
Example:
Run:
code
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:
code
R: This JSON string is valid!
See also: readjson()
, validdata()
History: Was introduced in 3.16.0.