Problem with json_query to search number

Hi all,

I am trying to search for a number with a json_query but result is always “”.

Part of JSON is:

“json”: {
“code”: 200,
“success”: true,
“data”: [
{
“vlanId”: “430”,
“domainId”: “3”,
“name”: “Default”,
“number”: “1”,
“description”: “Default VLAN”,
“editDate”: null,
“customer_id”: null,
“custom_Topdesk”: null
},
{
“vlanId”: “431”,
“domainId”: “3”,
“name”: “vlanname”,
“number”: “3”,
“description”: " vlanname ",
“editDate”: null,
“customer_id”: null,
“custom_Topdesk”: null
},

Ansible command i am using is:

  • name: Determine VLAN ID
    set_fact:
    vlan_id: “{{ ipam_vlans_filterby_domainid.content.data }} | json_query(‘[? number == ~ vlan ~]|[0].vlanId’) }}”

variabele vlan for example is: “3”

I found on internet there are some bugs regarding this and some work arounds but not able to get it solved.
Does some one has an idea?

Kind regards,

Danny

Try like

  • debug:
    msg: ‘{{ data | json_query(query) }}’
    vars:
    query: ‘[?number=="{{ vlan }}"]’