tidy the output to remove the last trailing comma and comments