Moved Json error handling to one place.