y HTML, or what I thought was HTML, was actually generating an object of type Twig_Markup rather than a string, and therefore wasn’t passing json validation.
Hmm. raw didn’t work.
But Twig_Markup has a magic method, __toString() which is called, magically, when Twig_Markup is printed. So, I just had to invoke that directly.
Which was as easy as:
{% set buttonHtml = buttonHtml.__toString(buttonHtml) %)
Happy coding!
References:


