JSONValid returns True for Invalid JSON text

In what appears to be my attempt to wear support out this week, I have discovered another one.

I have discovered that the JSONValid function can return True for text that is not valid JSON. This causes a runtime error when moving the text into a JSON variable

In the code below notice the comma after “LARGE”, that is not valid JSON!

However retVal comes back as True, and the assignment to the JSON variable tmpJSON doesn’t generate any errors either.

However, the next line with the Trace statement, attempting to display a value from the JSON variable causes a runtime error “The Variant variable is not an object”


x is string = [
{
    "Description": "LARGE",
}
]
retVal is boolean = JSONValid(x)
IF retVal THEN
	tmpJSON is JSON = x
	Trace(tmpJSON.Description)
ELSE 
	Info("Bad JSON")
END

2 thoughts on “JSONValid returns True for Invalid JSON text

  1. Yes if it would return False like it should, then I would not even try to move the string into the JSON variable. This is a vital test to prevent Webservices from crashing because of bad input

    Like

Leave a reply to Pete Halsted Cancel reply