1function IsJsonString(str) {
2 try {
3 JSON.parse(str);
4 } catch (e) {
5 return false;
6 }
7 return true;
8}
1function isValidJSONString(str) {
2 try {
3 JSON.parse(str);
4 } catch (e) {
5 return false;
6 }
7 return true;
8}
9//usage
10var personJSONString = '{"first_name":"Tony","last_name":"Hawk","age":31}';
11if(isValidJSONString(personJSONString)){
12 //cool we are valid, lets parse
13 var person= JSON.parse(personJSONString);
14}
15
1//extensive check to make sure object is not of string type and not null
2function isJson(item) {
3 item = typeof item !== "string"
4 ? JSON.stringify(item)
5 : item;
6
7 try {
8 item = JSON.parse(item);
9 } catch (e) {
10 return false;
11 }
12
13 if (typeof item === "object" && item !== null) {
14 return true;
15 }
16
17 return false;
18}