Reworked ErrorDict.as_json() to prevent unnecessary serialization/deserialization step.

Thanks @apollo13 for the suggestion. Refs #17413.