Passing JSON-encoded HTML from WordPress to JavaScript

While it’s not exact answer to your precise question, I agree with method suggest in comment. Just skip trying to stuff data into single dimension and make use of l10n_print_after argument instead.

See pass object/JSON to wp_localize_script question and answer there.