Better error handling for malformed JSON