# String being submitted when it should be an integer

**URL:** <https://forum.ansible.com/t/string-being-submitted-when-it-should-be-an-integer/4800>\
**Category:** Get Help\
**Tags:** playbook\
**Created:** [April 7, 2024, 2:40pm UTC](https://forum.ansible.com/t/string-being-submitted-when-it-should-be-an-integer/4800 "2024-04-07T14:40:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![GreatBigBear](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/greatbigbear/32/2828_2.png) [@GreatBigBear](https://forum.ansible.com/u/GreatBigBear)\
**Post date:** [April 7, 2024, 2:40pm UTC](https://forum.ansible.com/t/string-being-submitted-when-it-should-be-an-integer/4800/1 "2024-04-07T14:40:55Z")

</div>

First thank you for your help. 😀

A little background on what I am trying to accomplish. I am pulling a query via JSON and submitting to another API(Servicedesk). Every time I submit to service desk, the item variable is to be processed as a string. I need the quotes removed for submission. I have tried converting to (INT) and the data continues to be processed as a string. If I manually set the variable to the number it will submit correctly. here is what my output currently looks like.

(Grabbed from -vvv ansible output)  
“customfield\_1705”: “421266”  
and here is what i need it to look like  
“customfield\_1705”: 421266 (Requirement of servicedesk)

this is an example of how I submit the data.

- community.general.jira:  
args:  
fields:  
customfield\_1705: “{{json.[0].jmesquery}}”

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [April 7, 2024, 2:45pm UTC](https://forum.ansible.com/t/string-being-submitted-when-it-should-be-an-integer/4800/2 "2024-04-07T14:45:33Z")

</div>

What does the following return?

```yaml
- name: Debug customfield_1705
  ansible.builtin.debug:
    var: customfield_1705 | ansible.builtin.type_debug
  vars:
    customfield_1705: "{{ json.[0].jmesquery | int }}"
```

---

<div class="post-metadata">

**Author:** ![GreatBigBear](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/greatbigbear/32/2828_2.png) [@GreatBigBear](https://forum.ansible.com/u/GreatBigBear)\
**Post date:** [April 7, 2024, 3:38pm UTC](https://forum.ansible.com/t/string-being-submitted-when-it-should-be-an-integer/4800/3 "2024-04-07T15:38:49Z")

</div>

Before I convert to int it is a string. here is the output of type debug.

ok: [localhost] =\> {  
“msg”: [  
“str”  
]

If I set to INT and submit here is the output of that field

“{{json.[0].jmesquery | int }}”

“customfield\_1705”: “421266”

It looks like it gets converted back to a string?

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [April 7, 2024, 3:51pm UTC](https://forum.ansible.com/t/string-being-submitted-when-it-should-be-an-integer/4800/4 "2024-04-07T15:51:36Z")

</div>

Sorry I don’t have an answer to this ☹

---

<div class="post-metadata">

**Author:** ![GreatBigBear](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/greatbigbear/32/2828_2.png) [@GreatBigBear](https://forum.ansible.com/u/GreatBigBear)\
**Post date:** [April 7, 2024, 4:31pm UTC](https://forum.ansible.com/t/string-being-submitted-when-it-should-be-an-integer/4800/5 "2024-04-07T16:31:27Z")

</div>

@chris ,

no problem, I have no clue either. 😄

---

<div class="post-metadata">

**Author:** ![GreatBigBear](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/greatbigbear/32/2828_2.png) [@GreatBigBear](https://forum.ansible.com/u/GreatBigBear)\
**Post date:** [April 7, 2024, 5:56pm UTC](https://forum.ansible.com/t/string-being-submitted-when-it-should-be-an-integer/4800/6 "2024-04-07T17:56:08Z")

</div>

I found a solution. I needed to set the jinja2 Native to true. Feel free to look at this solution. Thank you.

> [@AWX and ANSIBLE\_JINJA2\_NATIVE=true](http://forum.ansible.com/t/awx-and-ansible-jinja2-native-true/4220):
>
> Hi need to run a template with the the value of ANSIBLE\_JINJA2\_NATIVE=true to fix a problem with URI module. I need to execute a POST with variables created with the set\_fact command that add double quotes (which must not be present). From CLI I solved it by prefixing ANSIBLE\_JINJA2\_NATIVE=True to the ansible-playbook command

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [April 7, 2024, 6:07pm UTC](https://forum.ansible.com/t/string-being-submitted-when-it-should-be-an-integer/4800/7 "2024-04-07T18:07:26Z")

</div>

In the normal course of things the result of Jinja templating is always a string (even for cases where it looks like it isn’t, that’s because Ansible converted it from a string into something else after templating.)

This isn’t a great user experience for Ansible, where a large number of non-string types are used, so there is a (currently optional) feature to enable preservation of types during templating. This will be the default in the future, but for now you can enable it if necessary. [Ansible Configuration Settings — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-jinja2-native)

Unfortunately this has the potential to break existing content that relied on the previous behaviour, so it requires careful testing to make nothing’s subtly wrong with this configuration enabled.

As an alternative, you can template more of the structure; since Ansible will parse a string that represents a dict back into a data structure, this can contain more types.

```yaml
- community.general.jira:
    fields: "{{ { 'customfield_1705': json.[0].jmesquery } }}"

```

---

<div class="post-metadata">

**Author:** ![GreatBigBear](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/greatbigbear/32/2828_2.png) [@GreatBigBear](https://forum.ansible.com/u/GreatBigBear)\
**Post date:** [April 7, 2024, 7:14pm UTC](https://forum.ansible.com/t/string-being-submitted-when-it-should-be-an-integer/4800/8 "2024-04-07T19:14:39Z")

</div>

oh Thank you very much. this works much better. I prefer not to make a global change for on variable. appreciate the help.

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [April 8, 2024, 1:34pm UTC](https://forum.ansible.com/t/string-being-submitted-when-it-should-be-an-integer/4800/9 "2024-04-08T13:34:49Z")

</div>

don’t use var to check types, it does ‘forced jsonization’, use msg:

```auto
- debug: msg="{{ json.[0].jmesquery | int| type_debug }}"

```

The trick is to always cast at consumption, if you do this in intermediate steps you might still get ‘stringified’, using the ‘native’ engine minimizes this but does not remove it. An upcoming change to the core way Ansible deals with types (Data Tagging) will hopefully fix this going forward.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 8, 2024, 1:34pm UTC](https://forum.ansible.com/t/string-being-submitted-when-it-should-be-an-integer/4800/10 "2024-05-08T13:34:50Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
