+ Start a Discussion

Platform Events: JSONGenerator adding \n & \r

Hello All,
    I have a need to send a platform event with the contents of an object put in a structured JSON format. Includes a few JSON arrays. 
For this, I used JSONGenerator, to structure my code:
//Sample code 

JSONGenerator gen = JSON.createGenerator(true);
gen.writeStringField('summary', this.summary);
gen.writeStringField('location', this.location);

and I followed the below article to structure the JSON


Now, I get the generator as a String and set it to a variable and subsequently assign it to a platform event's Text field.
String ganDetailsJSON = generator.getAsString();

The problem is the receiver of this platform event gets content with all \n. \r & \\ characters :
,\\r\\n \\\“accountNumber\\\” : \\\“88209\\\“,\\r\\n \\\“accountName\\\” : \\\“Harry Potter\\\“,\\r\\n \\\“adviserCode\\\” : \\\“14\\\“,\\r\\n \\\“branchCode\\\” : \\\“99\\\“,\\r\\n \\\“designation\\\”

How can I get rid of the additional characters that are added and make it more readable and parsable JSON format? 
If it was over a webservice, then converting it to a Blob would have helped. But given its a platform event and I need to set it in a tecxt field, is there any other way to work it out?