escapejson

Escapes the value for safe insertion into JSON strings.

For example:

{ "value": "{{ value | escapejson }}" }

When the value is he"llo then the output is he\"llo.

Or:

{ "title": "{{ id.title | unescape  | escapejson }}" }

In Zotonic text properties of resources are automatically html escaped. In order to transform them to correct JSON these values have to be unescaped first.

Internally, this calls z_utils:json_escape/1 to perform the string escaping.

Edit on GitHub

escapejs Character escaping escapexml

Referred by

escapejs

Escapes the value for insertion in JavaScript output.

Filters

Filters transform template variables before they are rendered.