# Boolean variable being capitalized in templates? Best practice to work around?

**URL:** <https://forum.ansible.com/t/boolean-variable-being-capitalized-in-templates-best-practice-to-work-around/17496>\
**Category:** Ansible Project\
**Created:** [February 10, 2015, 10:24pm UTC](https://forum.ansible.com/t/boolean-variable-being-capitalized-in-templates-best-practice-to-work-around/17496 "2015-02-10T22:24:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philip\_Lombardi](https://avatars.discourse-cdn.com/v4/letter/p/e274bd/32.png) [@Philip\_Lombardi](https://forum.ansible.com/u/Philip_Lombardi)\
**Post date:** [February 10, 2015, 10:24pm UTC](https://forum.ansible.com/t/boolean-variable-being-capitalized-in-templates-best-practice-to-work-around/17496/1 "2015-02-10T22:24:58Z")

</div>

I have some variables defined in a role such as:

`

---

<div class="post-metadata">

**Author:** ![Tom\_Bamford](https://avatars.discourse-cdn.com/v4/letter/t/c2a13f/32.png) [@Tom\_Bamford](https://forum.ansible.com/u/Tom_Bamford)\
**Post date:** [February 11, 2015, 7:48am UTC](https://forum.ansible.com/t/boolean-variable-being-capitalized-in-templates-best-practice-to-work-around/17496/2 "2015-02-11T07:48:15Z")

</div>

Hi Phil

Don’t know if there is an official short way to do this, but there is a ‘to\_json’ filter which seems to work on simple booleans, which could be slightly preferable to ‘lower’?

Tom

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 11, 2015, 1:38pm UTC](https://forum.ansible.com/t/boolean-variable-being-capitalized-in-templates-best-practice-to-work-around/17496/3 "2015-02-11T13:38:10Z")

</div>

the capitalized boolean happens because this is how valid booleans  
work in jinja2/python, which is what ansible uses internally.

as @tom suggested there is a to\_json filter which will output correct  
json from ansible data structures/variables.

---

<div class="post-metadata">

**Author:** ![Andrew\_Feller](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@Andrew\_Feller](https://forum.ansible.com/u/Andrew_Feller)\
**Post date:** [August 11, 2016, 1:15pm UTC](https://forum.ansible.com/t/boolean-variable-being-capitalized-in-templates-best-practice-to-work-around/17496/4 "2016-08-11T13:15:22Z")

</div>

Maybe to\_json is better than to\_yaml and apparently have been superseded by to\_nice\_json / to\_nice\_yaml but the to\_yaml / to\_nice\_yaml filters are crap, not well documented within jinja2, and require understanding the actual pyyaml library function interface to make work. In short, all of it feels bad.
