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

Referred by

Filters

escapejs

Escapes the value for insertion in JavaScript output.

Category

Filters

Template value transformations for text, collections, dates, numbers, URLs, and other data.