check if the string is valid JSON
bool isJson(String str) { try { json.decode(str); } catch (e) { return false; } return true; }