Skip to content

Instantly share code, notes, and snippets.

@kubosho
Created October 27, 2015 13:57
Show Gist options
  • Select an option

  • Save kubosho/01beb63e505f2d509fbc to your computer and use it in GitHub Desktop.

Select an option

Save kubosho/01beb63e505f2d509fbc to your computer and use it in GitHub Desktop.
isJSON
function isJson(item) {
item = typeof item !== "string"
? JSON.stringify(item)
: item;
try {
item = JSON.parse(item);
} catch (e) {
return false;
}
if (typeof item === "object" && item !== null) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment