Skip to content

Commit 9f0b20d

Browse files
authored
Check if a string is a valid JSON
1 parent 7b59f88 commit 9f0b20d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,5 +490,21 @@ span.addEventListener("click", function() {
490490
});
491491

492492
```
493+
# Check if a string is a valid JSON
494+
495+
```javascript
496+
function isJson(str) {
497+
try {
498+
JSON.parse(str);
499+
} catch (e) {
500+
//the json is not ok
501+
return false;
502+
}
503+
//the json is ok
504+
return true;
505+
}
506+
```
507+
508+
493509
494510

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy