JsonPath JUnit escape character for dots

后端 未结 3 1038
情书的邮戳
情书的邮戳 2020-12-05 14:54

I have a json field which is called template.welcome.email and I am writing a unit test that checks if that field is present in the reply from the server but I can\'t find a

相关标签:
3条回答
  • 2020-12-05 15:15

    These days (e.g. io.rest-assured.json-path:3.0.1) the notation seems to be without brackets:

    // Some Groovy OData V4 $count test
    // Response looks like:
    // { "@odata.count": 2, ... }
    body "'@odata.count'", equalTo(2)
    

    I found the corresponding hint in this Git issue.

    0 讨论(0)
  • 2020-12-05 15:30

    As Ida pointed out:

    Use brackets and quotes around your field. For example, if your field is valid.key.with.dot

    Refer to it as ['valid.key.with.dot'] and in JsonPath, try

    JsonPath.read(jsonString, "$.['valid.key.with.dot']")

    0 讨论(0)
  • 2020-12-05 15:35

    Use brackets and quotes around your field. For example, if your field is valid.key.with.dot

    Refer to it as ['valid.key.with.dot'] and in JsonPath, try

    JsonPath.read(jsonString, "$.['valid.key.with.dot']")
    

    See this thread also: https://groups.google.com/forum/#!topic/jsonpath/7YvgXWP1_7Y

    0 讨论(0)
提交回复
热议问题