uses System.SysUtils, System.JSON;
//ParseJSONValue returns nil when
//the string is broken
function IsValidJson(
const S: string): Boolean;
var
Value: TJSONValue;
begin
Value := TJSONObject.ParseJSONValue(S);
try
Result := Value <> nil;
finally
Value.Free;
end;
end;
const
Str1 = '{ "test": { "foo": "bar" } }';
Str2 = '{ "test": [ "foo": "bar" } }';
begin
WriteLn('valid1 is ', IsValidJson(Str1));
//valid1 is TRUE
WriteLn('valid2 is ', IsValidJson(Str2));
//valid2 is FALSE
end.