Escape '.' in JMESPath
Asked Answered
A

1

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?

Anadromous answered 3/7, 2019 at 14:47 Comment(1)
I have the same question.Heeheebiejeebies
H
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'

Heeheebiejeebies answered 5/7, 2019 at 19:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.