Search code examples
jmespath

Escape '.' in JMESPath


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?


Solution

  • 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'