From 551c9b9a21cece27fa535d33c70189211bb52b10 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 31 Dec 2017 15:12:16 +0200 Subject: [PATCH] Update isValidJSON.md --- snippets/isValidJSON.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/snippets/isValidJSON.md b/snippets/isValidJSON.md index 76257a007..dadefb897 100644 --- a/snippets/isValidJSON.md +++ b/snippets/isValidJSON.md @@ -2,15 +2,13 @@ Checks if the provided argument is a valid JSON. -Use `JSON.parse()` and a `try... catch` block to check if the provided argument is a valid JSON. +Use `JSON.parse()` and a `try... catch` block to check if the provided argument is a valid JSON and non-null. ```js const isValidJSON = obj => { try { JSON.parse(obj); - if (o && typeof o === "object") { - return true; - } + return !!obj; } catch (e) { return false; }