isJSON function returns true, when given string is valid JSON, and false otherwise

This commit is contained in:
Vladimir Khvan 2023-01-20 20:36:59 +05:00
parent 0c29d120ef
commit 32948dba92

View File

@ -0,0 +1,8 @@
export function isJSON(jsonString) {
try {
const parsedJson = JSON.parse(jsonString);
return parsedJson && typeof parsedJson === "object";
} catch (e) {}
return false;
}