Karate: JsonPath wildcards didn't work or partly didn't work

前端 未结 1 1673
忘了有多久
忘了有多久 2021-01-16 05:15

JSON file jsonExample:

{
  \"store\": {
    \"book\": [
      {
        \"category\": \"fiction\",
        \"author\": \"Evelyn Waugh\",
                


        
1条回答
  •  别那么骄傲
    2021-01-16 05:38

    I don't understand why you are so concerned with this. Wildcards will not work for updating JSON. It is that simple.

    And one more thing, eval will work with pure JS only. Json-Path is NOT pure JS.

    Maybe this will explain it more clearly.

    If * set jsonExample $..book[0].something = 13 is working please assume that it is a BUG. Do not rely on it. It may work in this case because the code is resilient as far as possible. But it may not work in other cases or in future versions of Karate.

    All the below will work:

    * def jsonExample =
    """
    {
      "store": {
        "book": [
          {
            "category": "fiction",
            "author": "Evelyn Waugh",
            "title": "Sword of Honour",
            "something": 12.99
          }
        ],
        "bicycle": {
          "color": "red",
          "price": 19.95
        }
      },
      "expensive": 10
    }
    """
    # all these will work
    * set jsonExample $.store.book[0].something = 13
    * match jsonExample.store.book[0].something == 13
    
    * set jsonExample.store.book[0].something = 14
    * match jsonExample.store.book[0].something == 14
    
    * eval jsonExample.store.book[0].something = 15
    * match jsonExample.store.book[0].something == 15
    

    I really hope this makes it clear !!

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