From 2cf844ebf5fc853986512226fc07cbabf8b9e653 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sun, 31 Dec 2017 15:17:27 +0200 Subject: [PATCH] Update isValidJSON.md --- snippets/isValidJSON.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/snippets/isValidJSON.md b/snippets/isValidJSON.md index ed7672a3a..5b671e67b 100644 --- a/snippets/isValidJSON.md +++ b/snippets/isValidJSON.md @@ -2,13 +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 and non-null. +Use `JSON.parse()` and a `try... catch` block to check if the provided argument is a valid JSON. ```js const isValidJSON = obj => { try { JSON.parse(obj); - return !!obj; + return true; } catch (e) { return false; } @@ -18,4 +18,5 @@ const isValidJSON = obj => { ```js isValidJSON('{"name":"Adam","age":20}'); // true isValidJSON('{"name":"Adam",age:"20"}'); // false +isValidJSON(null) // true ```