Handling errors for broken JSON

Viewed 3324

If the element #the-json is empty it will cause this error:

Uncaught SyntaxError: Unexpected end of input

For the following code:

myJSON = JSON.parse($("#the-json").attr('value'));

How should this error be handled so it doesn't stop the entire script working?

2 Answers
Related