Improving json to csv printer code