Better error handling on JSON parsing