Refactor error data extraction from JSON