- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Proper way to catch exception from JSON.parse
The best way to catch invalid JSON parsing errors is to put the calls to JSON.parse() to a try/catch block.
Example
function parseJSONSafely(str) { try { return JSON.parse(str); } catch (e) { console.err(e); // Return a default object, or null based on use case. return {} } }
Advertisements
To Continue Learning Please Login
Login with Google