jmespath / jmespath.py

JMESPath is a query language for JSON.

Home Page:http://jmespath.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with dictionary containing keys with COLON in string

anthonyxpalermo opened this issue · comments

in ansible
but this issue should be true with jmespath in general ?
I have a JSON Payload that looks like this
`
[
{
"domainPrefix": "hello.example.com",
"domainSuffix": "edgekey.net",
"edgeHostnameDomain": "hello.example.com.edgekey.net",
"edgeHostnameId": "ehn_7123",
"ipVersionBehavior": "IPV6_COMPLIANCE",
"mapDetails:mapDomain": "e43.dscj.akamaiedge.net",
"mapDetails:serialNumber": 0,
"mapDetails:slotNumber": 132520,
"secure": true,
"status": "CREATED"
}

]

`
and this is the code where I am trying to find info based on key mapDetails:slotNumber

name: Set an ansible fact from the akamai CPS certificate history JSON paylod for the active dictionary
set_fact:
pm_list_edge_related_to_slot: "{{ pm_list_edge_hostnames.msg.edgeHostnames| json_query(jmesquery) }}"
vars:
jmesquery: "items[? mapDetails:slotNumber==132520].{akamai_pm_edge_edgeHostnameId: edgeHostnameId,akamai_pm_edge_slotnumber: mapDetails:slotNumber }"
`

But what I get it the following

TASK [last_mile_akamai : Set an ansible fact from the akamai CPS certificate history JSON paylod for the active dictionary] *************************************************************************** fatal: [localhost]: FAILED! => {"msg": "JMESPathError in json_query filter plugin:\nExpecting: rbracket, got: colon: Parse error at column 18, token \":\" (COLON), for expression:\n\"items[? mapDetails:slotNumber==132520`].{akamai_pm_edge_edgeHostnameId: edgeHostnameId,akamai_pm_edge_slotnumber: 'slotNumber' }"\n ^"}

`

so my questions is how do I handle a key of a dictionary that is similar to this one ?
mapDetails:slotNumber
When I use it with mapDetails:slotNumber it always returns null

Turns out escaping correctly helps uh ?

jmesquery: "items[? \"mapDetails:slotNumber\"==2549]" #.{akamai_pm_edge_edgeHostnameId: edgeHostnameId, akamai_pm_edge_slotnumber: \"mapDetails:slotNumber\" }"