JSONPath Syntax when dot in key

Hayley picture Hayley · Oct 22, 2016 · Viewed 8k times · Source

Please forgive me if I use the incorrect terminology, I am quite the novice.

I have some simple JSON:

{
"properties": {
    "footer.navigationLinks": {
        "group": "layout"
    ,   "default": [
            {
                "text": "Link a"
            ,   "href": "#"
            }
        ]
    }
}
}

I am trying to pinpoint "footer.navigationLinks" but I am having trouble with the dot in the key name. I am using http://jsonpath.com/ and when I enter

$.properties['footer.navigationLinks']

I get 'No match'. If I change the key to "footernavigationLinks" it works but I cannot control the key names in the JSON file.

Please can someone help me target that key name?

Answer

Kotie Smit picture Kotie Smit · Nov 15, 2017

Having a json response:

{
  "0": {
    "SKU": "somevalue",
    "Merchant.Id": 234
    }
}

I can target a key with a . (dot) in the name.

jsonPath.getJsonObject("0.\"Merchant.Id\"")

Note: the quotes and the fact that they are escaped.

Note not sure of other versions, but I'm using

'com.jayway.restassured', name: 'json-path', version: '2.9.0'

A few samples/solutions I've seen, was using singe quotes with brackets, but did not work for me.