Skip to content
Zotonic
  • Start
  • Cookbook
  • Reference
  • Releases

Live search

Search across all Zotonic content

Type at least two characters

Results are matched against titles, summaries and topics as you type.

Filters ยท mod_base
  • Reference
  • Frontend developer
  • Template filter
  • Serialize
  • JSON

to_json

Module

mod_base

Display any value as in JSON (JavaScript Object Notation).

For example:

{{ [1,2,3]|to_json }}

Converts this list to a valid JSON UTF-8 encoded string which can be directly used in JavaScript calls.

Another example for a JSON object:

{{ %{ a: 1, b: 2 }|to_json }}

Edit on GitHub

Related documentation

Filters

escapejson

Escapes the value for safe insertion into JSON strings.

Filters

from_json

Parse a string as a JSON (JavaScript Object Notation) value. The returned value can be processed futher.

Filters

urlencode

Make a text safe for URLs.

Filters

url_abs

Generates an absolute URL for the given dispatch information.

Filters

pickle

Pickle an Erlang value so that it can be safely submitted with a form.

Filters

escapexml

Escape the value for insertion in xml output.

Filters

escape_ical

Escape the value according to the RFC2445 rules.

Filters

url

Generates the relative URL for the given dispatch information.

Filters

flatten_value

Flatten a list to a comma separated string.

GitHub © 2026 Zotonic