Handle JSON parsing errors

Aaand final PR of the day from me (I should start consolidating these or something).

Does exactly what it says on the tin.