Merge pull request #439 from kriadmin/patch-2

Update isValidJSON.md
This commit is contained in:
Angelos Chalaris
2017-12-31 15:13:45 +02:00
committed by GitHub

View File

@ -2,14 +2,14 @@
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);
return true;
} catch (e) {
return !!obj;
} catch (e) {
return false;
}
};