Remove bracket and u from json data in ansi le

Hello All,

I want remove bracket and u from json data in ansible. I am trying to retrieve data from json.
I executed this code in playbook

  • debug:
    msg: “{{ item }}”
    loop: “{{ raidurl1 | json_query(‘json.Members[].[]’) }}”

I am getting output like

(item=[[u’ /refish/v1/Systems/1’]])

But i want output like
(item= /redfish/v1/Systems/1 )

How can i remove bracket and u from item. Do i need to change anything in to debug loop? Please help

Thanks and regards,
Abhi

Try piping thru “from_json | to_json” or just “to_json” filter. One of those worked for me. Cannot remember which one.

Walter

I tried earlier but no luck… Any other suggestions?

The bracket and the u are not just some stray characters, which you seem to think.
Your data is structured like a nested list, and that is what is being displayed.
Adjust the json_query to remove the nested structure.

Also you didn’t post your raidurl1 data so it’s mostly guessing…

Hi dick,

Please check raidurl1 output attached. Please advice…

Regards,
Abhijit

(attachments)

raidurl1[‘json’].Members should get you Members JSON list.

raidurl1 | json_query(‘json.Members[*].@odata.od’)

OR

raidurl1.json.Members | json_query(‘[*].@odata.od’)

Walter

https://docs.ansible.com/ansible/5/collections/community/general/docsite/filter_guide_selecting_json_data.html

Walter

This is the latest documentation.

https://docs.ansible.com/ansible/latest/collections/community/general/json_query_filter.html

Walter

I tried this things as well but getting error… attached screenshot

Regards,
Abhi

(attachments)

I sense it doesn’t like the @ sign as part of an identifier.

Walter