isJson method
Checks if the String
is a valid json
format.
Example
String foo = '{"name":"John","age":30,"cars":null}';
bool isJson = foo.isJson; // returns true
Implementation
bool isJson() {
if (this.isBlank) {
return false;
}
try {
jsonDecode(this);
return true;
} catch (e) {
return false;
}
}