You can format the string by adding options to the JSON.stringify() method. To format the code, use
JSON.stringify(myCode, null, 2)
The second argument is a replacer, see documentation; the third argument is the number of spaces used for formatted code indentation.
Docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify