To save generating all the JSON each time (which will probably give a performance hit as we get more certificates), I'm getting certificates which have been updated recently, generating a JSON string from a partial, parsing that and then modifying or appending it to the JSON hash, then converting the hash back to a JSON string for uploading. I've added some comments to be a bit clearer.