Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

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

Input:

{{ site | to_json }}

Output:

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

Input:

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

Output:

[["param_key_1", "param_val_1"], ["param_key_2", "param_val_2"]]

If you want to convert a hash to key/value JSON, you can pass true as an argument. Plate Objects get converted to key/value JSON regardless of the passed argument.

Input:

# params = { 'param_key_1' => 'param_val_1', 'param_key_2' => 'param_val_2' }
{{ params | to_json: true }}

Output:

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

  • No labels