Safely escape Twig's json_encode() without using raw
Twig will sometimes escape output, which can be a real problem if you're relying on it to build your web page or provide data to something like a piece of JavaScript. Twig's raw provides an easy solution to this, but opens up a realm of potential security issues leaving you more vulnerable than you think. Here's another solution to help you stay secure and get the job done.