From e59829b9efeca105b0757939447bd28a1c5c647d Mon Sep 17 00:00:00 2001 From: Rohit Tanwar <31792358+kriadmin@users.noreply.github.com> Date: Sun, 31 Dec 2017 18:38:09 +0530 Subject: [PATCH] Update isValidJSON.md --- snippets/isValidJSON.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/snippets/isValidJSON.md b/snippets/isValidJSON.md index e9898caee..76257a007 100644 --- a/snippets/isValidJSON.md +++ b/snippets/isValidJSON.md @@ -8,8 +8,10 @@ Use `JSON.parse()` and a `try... catch` block to check if the provided argument const isValidJSON = obj => { try { JSON.parse(obj); - return true; - } catch (e) { + if (o && typeof o === "object") { + return true; + } +} catch (e) { return false; } };