# How does {{ timeout|default(0)|json }} work?

**URL:** <https://discourse.bokeh.org/t/how-does-timeout-default-0-json-work/5014>\
**Category:** Community Support\
**Created:** [March 26, 2020, 6:54am UTC](https://discourse.bokeh.org/t/how-does-timeout-default-0-json-work/5014 "2020-03-26T06:54:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arihans](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/arihans/32/1805_2.png) [@arihans](https://discourse.bokeh.org/u/arihans)\
**Post date:** [March 26, 2020, 6:54am UTC](https://discourse.bokeh.org/t/how-does-timeout-default-0-json-work/5014/1 "2020-03-26T06:54:56Z")

</div>

How does {{ timeout|default(0)|json }} work?

```auto
// bokeh/bokeh/core/_templates/autoload_nb_js.js:134,135

if (typeof (root._bokeh_timeout) === "undefined" || force === true) {
    root._bokeh_timeout = Date.now() + {{ timeout|default(0)|json }};

```

My guess was that the `default(0)` sets the default for variable `timeout` to `0` and the `json` converts it to string `'0'`. Not sure why you would do that.  
I couldn’t find any `default()` _(in this syntax)_ and `json` filter in django template builtins.

---

<div class="post-metadata">

**Author:** ![p-himik](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/p-himik/32/4010_2.png) [@p-himik](https://discourse.bokeh.org/u/p-himik)\
**Post date:** [March 26, 2020, 8:31am UTC](https://discourse.bokeh.org/t/how-does-timeout-default-0-json-work/5014/2 "2020-03-26T08:31:39Z")

</div>

You couldn’t find the filters because Bokeh doesn’t use Django, it uses Jinja templates.  
The `default` filter: [Template Designer Documentation — Jinja Documentation (3.0.x)](https://jinja.palletsprojects.com/en/2.11.x/templates/#default)  
And the `json` filter: [bokeh/templates.py at branch-3.0 · bokeh/bokeh · GitHub](https://github.com/bokeh/bokeh/blob/master/bokeh/core/templates.py#L87)

For why there is the `json` filter, I am not sure. It doesn’t change the value into a string because the template system handles it. It seems that it’s there just to make sure that we use only well-formed JSON values in JS files. Here’s the PR if you’re interested: [Fix autoload templates to inject data into JS templates properly by mattpap · Pull Request #5603 · bokeh/bokeh · GitHub](https://github.com/bokeh/bokeh/pull/5603)

---

<div class="post-metadata">

**Author:** ![system](https://discourse-uploads.bokeh.org/original/2X/1/14eb24f9e10e4e9b78e3f10f66c04ffa96446e5a.svg) [@system](https://discourse.bokeh.org/u/system)\
**Post date:** [July 21, 2021, 9:23pm UTC](https://discourse.bokeh.org/t/how-does-timeout-default-0-json-work/5014/3 "2021-07-21T21:23:14Z")

</div>


