You can use PHPs output buffering, using ob_start to turn on the buffering and ob_get_clean to get and delete the current output buffering.
So going by your code it would look like this
<section class="blog container spacer">
After examining the code using developer tools, I was able to figure out the problem. Code was being wrapped in the pre tags which were causing the code to break its proper structure.
Found the solution for the pre tags issue here which solved the problem.
Ultimately, I solved the problem by exporting the wp_posts table from the database and doing a regex search along the lines of
'([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]', '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9])', '(.*?)\[soundcloud url=\\"http://api\.soundcloud\.com/tracks/(.*?)\\&...
This is unnecessary, WordPress already provides the fully rendered HTML content in REST responses with the shortcodes already processed and turned into HTML. Inside the object the API responds with is a content field that has a rendered sub-field containing what you want. Use that instead of the raw unprocessed version.