Imply the |safe on tojson in templates and change escaping logic