const isJSON = (params) => { let flag = false if(typeof params === 'string'){ try{ let obj = JSON.parse(params) if(obj && typeof obj === 'object'){ flag = true }else{ flag = false } }catch(e){ flag = false } } return flag } console.log( isJSON('foo') ) JSON.parse('123'); // 123 JSON.parse('true'); // true JSON.parse('"foo"'); // "foo" JSON.parse('null'); // null JSON.parse('[1, 5, "false"]'); // [1, 5, "false"] JSON.parse('{}'); // {}