to_json

Turns input into JSON, when possible. If input cannot be turned into JSON object, the filter just returns the input again.

Input:

1 {{ site | to_json }}

Output:

1 {"id": 783, "content_type": { "name": "site", "title": "Site" }, "name": "A beautiful Site", ...}

Input:

1 2 # params = { 'param_key_1' => 'param_val_1', 'param_key_2' => 'param_val_2' } {{ params | to_json }}

Output:

1 {"param_key_1": "param_val_1", "param_key_2": "param_val_2"}