Created
October 27, 2015 13:57
-
-
Save kubosho/01beb63e505f2d509fbc to your computer and use it in GitHub Desktop.
isJSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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