# To\_json not working in Ansible 2.19.0rc2

**URL:** <https://forum.ansible.com/t/to-json-not-working-in-ansible-2-19-0rc2/43879>\
**Category:** Get Help\
**Created:** [July 15, 2025, 11:28am UTC](https://forum.ansible.com/t/to-json-not-working-in-ansible-2-19-0rc2/43879 "2025-07-15T11:28:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![trisha-dell](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/trisha-dell/32/8640_2.png) [@trisha-dell](https://forum.ansible.com/u/trisha-dell)\
**Post date:** [July 15, 2025, 11:28am UTC](https://forum.ansible.com/t/to-json-not-working-in-ansible-2-19-0rc2/43879/1 "2025-07-15T11:28:11Z")

</div>

The to\_json filter is not working to covert a string to json.  
Eg.  
Input: “msg”: “{‘Key’: ‘\<null\_index\>’, ‘DeleteOnCompletion’: ‘false’, ‘InstanceID’: ‘DCIM\_OSDConcreteJob:1’, ‘JobName’: ‘BootToNetworkISO’, ‘JobStatus’: ‘Failed’, ‘Message’: ‘Unable to locate the ISO image on the network share point.’, ‘MessageArguments’: None, ‘MessageID’: ‘OSD18’, ‘Name’: ‘BootToNetworkISO’, ‘Status’: ‘Failed’, ‘retval’: False, ‘file’: ‘/nfsshare/invalid.iso’}”

task:  
- name: Set result\_iso\_invalid message  
ansible.builtin.set\_fact:  
result\_iso\_invalid\_msg: “{{ msg | to\_json }}”

Actual result:  
“ansible\_facts”: {  
“result\_iso\_invalid\_msg”: “"{‘Key’: ‘\<null\_index\>’, ‘DeleteOnCompletion’: ‘false’, ‘InstanceID’: ‘DCIM\_OSDConcreteJob:1’, ‘JobName’: ‘BootToNetworkISO’, ‘JobStatus’: ‘Failed’, ‘Message’: ‘Unable to locate the ISO image on the network share point.’, ‘MessageArguments’: None, ‘MessageID’: ‘OSD18’, ‘Name’: ‘BootToNetworkISO’, ‘Status’: ‘Failed’, ‘retval’: False, ‘file’: ‘/nfsshare/invalid.iso’}"”  
}

Expected result:  
“result\_iso\_invalid\_msg”: {  
“DeleteOnCompletion”: “false”,  
“InstanceID”: “DCIM\_OSDConcreteJob:1”,  
“JobName”: “BootToNetworkISO”,  
“JobStatus”: “Failed”,  
“Key”: “\<null\_index\>”,  
“Message”: “Unable to locate the ISO image on the network share point.”,  
“MessageArguments”: “None”,  
“MessageID”: “OSD18”,  
“Name”: “BootToNetworkISO”,  
“Status”: “Failed”,  
“file”: “/nfsshare/invalid.iso”,  
“retval”: false  
}

Instead of to\_json, when from\_yaml is used, this works fine.

Has to\_json been deprecated?

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [July 15, 2025, 1:05pm UTC](https://forum.ansible.com/t/to-json-not-working-in-ansible-2-19-0rc2/43879/2 "2025-07-15T13:05:11Z")

</div>

It sounds like the string is already JSON (in which case, you’d need to use `from_json` not `to_json`).

Can you share an example of specifically what was working before 2.19? The quotation marks in your example input are a little ambiguous to me (not valid json).

---

<div class="post-metadata">

**Author:** ![trisha-dell](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/trisha-dell/32/8640_2.png) [@trisha-dell](https://forum.ansible.com/u/trisha-dell)\
**Post date:** [July 15, 2025, 1:53pm UTC](https://forum.ansible.com/t/to-json-not-working-in-ansible-2-19-0rc2/43879/3 "2025-07-15T13:53:24Z")

</div>

Hello @shertel,

Thank you for responding:  
This is the set of tasks used:  
- name: Boot to Network ISO with nfs share (iso\_invalid)  
idrac\_os\_deployment:  
share\_name: “{{nfs\_share\_name}}”  
iso\_image: “invalid.iso”  
expose\_duration: 5  
ignore\_errors: true  
register: result\_iso\_invalid

```
- name: Set result_iso_invalid message
  ansible.builtin.set_fact:
    result_iso_invalid_msg: "{{ result_iso_invalid.msg | from_json }}"

```

The first task returns:  
{  
“changed”: false,  
“invocation”: {  
“module\_args”: {  
“ca\_path”: null,  
“expose\_duration”: 5,  
“idrac\_ip”: “xx.xx.xx.xx”,  
“idrac\_password”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“idrac\_port”: 443,  
“idrac\_user”: “root”,  
“iso\_image”: “invalid.iso”,  
“share\_name”: “/nfsshare”,  
“share\_password”: null,  
“share\_user”: null,  
“timeout”: 30,  
“validate\_certs”: false  
}  
},  
“msg”: “{‘Key’: ‘\<null\_index\>’, ‘DeleteOnCompletion’: ‘false’, ‘InstanceID’: ‘DCIM\_OSDConcreteJob:1’, ‘JobName’: ‘BootToNetworkISO’, ‘JobStatus’: ‘Failed’, ‘Message’: ‘Unable to locate the ISO image on the network share point.’, ‘MessageArguments’: None, ‘MessageID’: ‘OSD18’, ‘Name’: ‘BootToNetworkISO’, ‘Status’: ‘Failed’, ‘retval’: False, ‘file’: ‘/nfsshare/invalid.iso’}”  
}

The second task then returns:  
{  
“changed”: false,  
“msg”: “Task failed: Finalization of task args for ‘ansible.builtin.set\_fact’ failed: Error while resolving value for ‘result\_iso\_invalid\_msg’: The filter plugin ‘ansible.builtin.from\_json’ failed: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)”  
}

In 2.18, the first task returned this:  
{  
“changed”: false,  
“invocation”: {  
“module\_args”: {  
“ca\_path”: null,  
“expose\_duration”: 5,  
“idrac\_ip”: “xx.xx.xx.xx”,  
“idrac\_password”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“idrac\_port”: 443,  
“idrac\_user”: “root”,  
“iso\_image”: “invalid.iso”,  
“share\_name”: “/nfsshare”,  
“share\_password”: null,  
“share\_user”: null,  
“timeout”: 30,  
“validate\_certs”: false  
}  
},  
“msg”: {  
“DeleteOnCompletion”: “false”,  
“InstanceID”: “DCIM\_OSDConcreteJob:1”,  
“JobName”: “BootToNetworkISO”,  
“JobStatus”: “Failed”,  
“Key”: “\<null\_index\>”,  
“Message”: “Unable to locate the ISO image on the network share point.”,  
“MessageArguments”: null,  
“MessageID”: “OSD18”,  
“Name”: “BootToNetworkISO”,  
“Status”: “Failed”,  
“file”: “/nfsshare/invalid.iso”,  
“retval”: false  
}  
}

In 2.18, the msg returned was in dict form so the msg keys could be handled without using from\_jsom/from\_yaml.

Is this change expected?

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [July 15, 2025, 2:09pm UTC](https://forum.ansible.com/t/to-json-not-working-in-ansible-2-19-0rc2/43879/4 "2025-07-15T14:09:13Z")

</div>

It looks like msg should be a string: [dellemc-openmanage-ansible-modules/plugins/modules/idrac\_os\_deployment.py at collections · dell/dellemc-openmanage-ansible-modules · GitHub](https://github.com/dell/dellemc-openmanage-ansible-modules/blob/collections/plugins/modules/idrac_os_deployment.py#L73). I wonder why it wasn’t before.

It might be a bug related to the module, not `to_json`. There’s an open issue here to validate compatibility with 2.19: [Validate compatibility with ansible-core 2.19 · Issue #854 · dell/dellemc-openmanage-ansible-modules · GitHub](https://github.com/dell/dellemc-openmanage-ansible-modules/issues/854).

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [July 15, 2025, 2:27pm UTC](https://forum.ansible.com/t/to-json-not-working-in-ansible-2-19-0rc2/43879/5 "2025-07-15T14:27:00Z")

</div>

@trisha-dell My mistake, I do see auto JSON conversion for string types. We may need to add a porting guide entry if there isn’t already one. I have brought it up internally.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [July 15, 2025, 2:27pm UTC](https://forum.ansible.com/t/to-json-not-working-in-ansible-2-19-0rc2/43879/6 "2025-07-15T14:27:02Z")

</div>

I did some tests, ansible-core 2.19 converts `msg` to a string if `AnsibleModule.fail_json()` is called, while 2.18 does not do that. This also does not happen for `AnsibleModule.exit_json()`. (I’m not sure whether this happens in the module or in the controller code, but `-vvv` output already shows the stringified value for `msg` for the task.)
