5

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?

Thorkil Holm-Jacobsen
  • 7,287
  • 5
  • 30
  • 43

1 Answers1

13

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'

JAponte
  • 1,508
  • 1
  • 13
  • 21