Better error handling for json