const isValidJSON = string => { try { JSON.parse(string); return true; } catch (error) { return false; } }; let check1 = isValidJSON(‘{“title”: “javascript”, “price”: 14}’); // true let check2 = isValidJSON(‘{“title”: “javascript”, “price”: 14, subtitle}’); // false
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter