Warm tip: This article is reproduced from stackoverflow.com, please click
jmespath

Escape '.' in JMESPath

发布于 2020-03-27 10:25:12

I have a JSON object in which I wish to retrieve the value of a property that contains a dot in its name using JMESPath:

{
  "a": {
    "b.c": "value"
  }
}

In this example I wish to retrieve value. How can I achieve this?

Questioner
Thorkil Holm-Jacobsen
Viewed
41
JAponte 2019-07-06 03:34

I just figured it out. I'm working in python, but I think the solution is the same for any implementation. Basically, any key name with special characters need to be quoted within the search string. With your example:

import jmespath

test_dictionary = {
  "a": {
    "b.c": "value"
  }
}

jmespath.compile('a."b.c"').search(test_dictionary)

Result: 'value'