Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

Ansible compare two JSON responses

$
0
0

I'm using Ansible to call the same administration API on two different servers and then selecting the core details of the applications from the responses using jq.

According to Ansible type_debug the registered variables are of type dict

ok: [localhost] => {"node1_applications | type_debug": "dict"}
ok: [localhost] => {"node2_applications | type_debug": "dict"}

The JSON from the two responses looks like

{"Node": "ESB1","AppCoreDetails": [    {"ApplicationName": "APP_Config_V1","LastModified": "2023-08-25 12:23:26"    },    {"ApplicationName": "APP_Intervals_V1","LastModified": "2022-11-23 14:46:58"    }  ]}
{"Node": "ESB2","AppCoreDetails": [    {"ApplicationName": "APP_Config_V1","LastModified": "2023-08-25 12:03:30"    },    {"ApplicationName": "APP_Intervals_V1","LastModified": "2022-11-23 14:46:58"    }  ]}

Where the LastModified date of the first entry in AppCoreDetails is different and for the second entry it's the same.

I'd like to get the set of objects where the LastMofified dates are different.

{"AppCoreDetails": [    {"ApplicationName": "APP_Config_V1","LastModified": "2023-08-25 12:23:26"    }  ]}

BTW I found and tried experimenting with this but failed to convert from simple fields to objects enter link description here


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>