filter_escapejson (zotonic_mod_base v1.0.0-rc.17)

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.

See also

escape, escapejs

Summary

Functions

escapejson(Value, Context)

-spec escapejson(Value, Context) -> iodata() when Value :: term(), Context :: z:context().