"For developers", "Server scripts", "Functions description", "JSON", "JSONValid".
Check if the syntax of JSON object is correct by its text string.
function JSONValid(const sJSON: string): boolean;
Parameter |
Type |
Value |
---|---|---|
sJSON |
string |
JSON object as a text string. |
"True" if the object is correct, "False" if syntax has errors.
const
JSONObj1 = '{"myvalue":17}';
JSONObj2 = '["Hello, world!"]';
JSONObj3 = 'When nights were cold I wandered without you';
begin
if JSONValid(JSONObj1) then mLogScript(JSONObj1, 'Ok')
else mLogScript(JSONObj1, 'Invalid JSON!');
if JSONValid(JSONObj2) then mLogScript(JSONObj2, 'Ok')
else mLogScript(JSONObj2, 'Invalid JSON!');
if JSONValid(JSONObj3) then mLogScript(JSONObj3, 'Ok')
else mLogScript(JSONObj3, 'Invalid JSON!');
end.
[19:27:58] (Log "JSONValid"): [Ok] {"myvalue":17}
[19:27:58] (Log "JSONValid"): [Invalid JSON!] ["Hello, world!"]
[19:27:58] (Log "JSONValid"): [Invalid JSON!] When nights were cold I wandered without you
[19:27:58] (Run "JSONValid"): Script operation time: 9 ms
[19:27:58] (Run "JSONValid"): Script done successfully.