Check if the syntax of JSON object is correct by its text string.

 

Syntax

function JSONValid(const sJSON: string): boolean;

 

Parameters and return values

Parameter

Type

Value

sJSON

string

JSON object as a text string.

 

Function result

"True" if the object is correct, "False" if syntax has errors.

 

Example


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.


Script work result

[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.

 

See also

mLogScript