Remove bracket and u from json data in ansi le

250 views
Skip to first unread message

Linux Study

unread,
Jan 25, 2023, 2:39:34 AM1/25/23
to ansible...@googlegroups.com
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

Rowe, Walter P. (Fed)

unread,
Jan 25, 2023, 8:52:31 AM1/25/23
to ansible...@googlegroups.com
Try piping thru "from_json | to_json" or just "to_json" filter. One of those worked for me. Cannot remember which one.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEcjLFwnqUC727hEDyW%2BoAiM%2B7hCOm3sNcA-oQ54JNvvHYob6A%40mail.gmail.com.

Linux Study

unread,
Jan 25, 2023, 11:45:11 AM1/25/23
to ansible...@googlegroups.com
I tried earlier but no luck... Any other suggestions?



Dick Visser

unread,
Jan 25, 2023, 1:46:09 PM1/25/23
to ansible...@googlegroups.com
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...


On Wed, 25 Jan 2023 at 17:45, Linux Study <linux...@gmail.com> wrote:
I tried earlier but no luck... Any other suggestions?
On Wed, 25 Jan 2023, 19:22 'Rowe, Walter P. (Fed)' via Ansible Project, <ansible...@googlegroups.com> wrote:
Try piping thru "from_json | to_json" or just "to_json" filter. One of those worked for me. Cannot remember which one.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
On Jan 25, 2023, at 2:39 AM, Linux Study <linux...@gmail.com> wrote:

Hello All,

I wantremove 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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEcjLFwnqUC727hEDyW%2BoAiM%2B7hCOm3sNcA-oQ54JNvvHYob6A%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/757E593A-9436-4CA5-A795-C9473E0985DA%40nist.gov.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
--
Sent from Gmail Mobile

Linux Study

unread,
Jan 27, 2023, 2:05:20 AM1/27/23
to ansible...@googlegroups.com
Hi dick,

 Please check raidurl1 output attached. Please advice...

Regards,
Abhijit

IMG_20230127_123227.jpg

Rowe, Walter P. (Fed)

unread,
Jan 27, 2023, 8:07:18 AM1/27/23
to ansible...@googlegroups.com
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
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

Rowe, Walter P. (Fed)

unread,
Jan 27, 2023, 8:09:36 AM1/27/23
to ansible...@googlegroups.com

Rowe, Walter P. (Fed)

unread,
Jan 27, 2023, 8:28:41 AM1/27/23
to ansible...@googlegroups.com


Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

Linux Study

unread,
Jan 28, 2023, 2:18:28 AM1/28/23
to ansible...@googlegroups.com
I tried this things as well but getting error... attached screenshot


Regards, 
Abhi



IMG_20230128_124419.jpg

Rowe, Walter P. (Fed)

unread,
Jan 30, 2023, 7:29:25 AM1/30/23
to ansible...@googlegroups.com
I sense it doesn't like the @ sign as part of an identifier.


Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
Reply all
Reply to author
Forward
0 new messages