json: cleanup and add more parameters for writing.