Below is my json file:
[
{
"?xml": {
"attributes": {
"encoding": "UTF-8",
"version": "1.0"
}
}
},
{
"domain": [
{
"server": [
{
"name": "myserv1"
},
{
"ssl": {
"name": "myserv1"
}
},
{
"log": [
{
"name": "myserv1"
},
{
"file-name":
"/web/bea_logs/domains/mydom/myserv1/myserv1.log"
}
]
}
]
},
{
"server": [
{
"name": "myserv2"
},
{
"ssl": {
"name": "myserv2"
}
},
{
"log": [
{
"name": "myserv2"
},
{
"file-name":
"/web/bea_logs/domains/mydom/myserv2/myserv2.log"
}
]
},
]
}
]
}
]
I wish to parse the above json and get the data like below:
myserv1_log: /web/bea_logs/domains/mydom/myserv1/myserv1.log
myserv2_log: /web/bea_logs/domains/mydom/myserv2/myserv2.log
Below is how i try to parse the json using jmespath:
- name: Server Names and log details
set_fact:
serverlog: "{{ jsondata | json_query(jmesquery) }}"
vars:
jmesquery: '[].domain[].server[*].log[*].[name, "file-name"]'
- name: Print all server names with log details
debug:
msg: "{{ item }}"
with_items:
- "{{ serverlog }}"
Issue is that I'm getting null in the output as below:
ok: [localhost] => (item=[[['myserv1', None], [None,
'/web/bea_logs/domains/mydom/myserv1/myserv1.log']]]) => {
"msg": [
[
[
"myserv1",
null
],
[
null,
"/web/bea_logs/domains/mydom/myserv1/myserv1.log"
]
]
]
}
ok: [localhost] => (item=[[['myserv2', None], [None,
'/web/bea_logs/domains/mydom/myserv2/myserv2.log']]]) => {
"msg": [
[
[
"myserv2",
null
],
[
null,
"/web/bea_logs/domains/mydom/myserv2/myserv2.log"
]
]
]
}
Can you please suggest ?
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/0c7ba194-dcff-4244-ad0c-999b09f3e7c4n%40googlegroups.com.