Learn JavaScript
Error Handling
36.4
Lesson

Verify JSON with try...catch

The JSON format is used to send and receive data over the internet.

We use JSON.parse() to convert a JSON string into an object. If JSON data is not valid, JSON.parse() generates an error. But it stops the execution of the code without showing any error message to the user.

We can use try...catch to check the validity of JSON data and show an error message to the user.