check if the string is valid JSON
bool isJSON(String str) { try { jsonDecode(str); } catch (e) { return false; } return true; }