Better error handling in JSON parsing