# help avoiding u" prefixes on template generated output of a dictionary

**URL:** <https://forum.ansible.com/t/help-avoiding-u-prefixes-on-template-generated-output-of-a-dictionary/16324>\
**Category:** Ansible Project\
**Created:** [September 24, 2014, 6:48pm UTC](https://forum.ansible.com/t/help-avoiding-u-prefixes-on-template-generated-output-of-a-dictionary/16324 "2014-09-24T18:48:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kesten\_broughton1](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@kesten\_broughton1](https://forum.ansible.com/u/kesten_broughton1)\
**Post date:** [September 24, 2014, 6:48pm UTC](https://forum.ansible.com/t/help-avoiding-u-prefixes-on-template-generated-output-of-a-dictionary/16324/1 "2014-09-24T18:48:45Z")

</div>

```auto

The goal is to define a dictionary like
 
dict1:
 int1: 5
 str1: "four"
 
and be able to template output the dictionary as a whole (not leaf by leaf) such that the output looks like
 
dict1: {"int1": 5, "srt1": "four"}
 
The actual output prefixes the values on the RHS of the : with a u so it looks like
dict1: {"int1": u"5", "srt1": u"four"}
 

```

dict1: {“int1”: u"5", “srt1”: u"four"}

Please see the gist for details.  
[https://gist.github.com/darKoram/3f2fbcc9b3a003546f3c](https://gist.github.com/darKoram/3f2fbcc9b3a003546f3c)

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 24, 2014, 6:54pm UTC](https://forum.ansible.com/t/help-avoiding-u-prefixes-on-template-generated-output-of-a-dictionary/16324/2 "2014-09-24T18:54:03Z")

</div>

You should probably use either the to\_nice\_yaml or to\_yaml filters

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 24, 2014, 6:55pm UTC](https://forum.ansible.com/t/help-avoiding-u-prefixes-on-template-generated-output-of-a-dictionary/16324/3 "2014-09-24T18:55:49Z")

</div>

So that’s just indicating unicode output, I’m curious if it’s causing any specific problems for you?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 24, 2014, 6:58pm UTC](https://forum.ansible.com/t/help-avoiding-u-prefixes-on-template-generated-output-of-a-dictionary/16324/4 "2014-09-24T18:58:01Z")

</div>

An example being:

dict1: {{dict1|to\_yaml}}

Which produces:

dict1: {\_int1: ‘5’, \_str1: four}

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 24, 2014, 7:00pm UTC](https://forum.ansible.com/t/help-avoiding-u-prefixes-on-template-generated-output-of-a-dictionary/16324/5 "2014-09-24T19:00:01Z")

</div>

Oh, nm, you mean templating the directionary. Got it, there is also

{{ dict | to\_nice\_json }}

as well

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 24, 2014, 7:00pm UTC](https://forum.ansible.com/t/help-avoiding-u-prefixes-on-template-generated-output-of-a-dictionary/16324/6 "2014-09-24T19:00:21Z")

</div>

Are those underscores before the names of the keys typos?

---

<div class="post-metadata">

**Author:** ![kesten\_broughton1](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@kesten\_broughton1](https://forum.ansible.com/u/kesten_broughton1)\
**Post date:** [September 25, 2014, 5:58pm UTC](https://forum.ansible.com/t/help-avoiding-u-prefixes-on-template-generated-output-of-a-dictionary/16324/7 "2014-09-25T17:58:38Z")

</div>

Thanks matt. to\_yaml worked great.

The underscores…  
I use hash\_behavior = merge and i’ve found that if i define parts of the dict across different files then a statement like

dict1: {{dict1}}

will fail with a “recursive definition detected” message. I was being defensive. In this case, it worked fine removing the underscores from the vars.

k
