【问题标题】:How can I convert to Json Object to Json Array in Karate?如何在空手道中将 Json 对象转换为 Json 数组?
【发布时间】:2019-11-22 10:11:05
【问题描述】:

我想在空手道中将 Json Object 转换为 Json Array 以使用 'match each' 函数。 当我将每个函数与 Json 对象匹配时,我遇到 ('match each' failed, not a json array) 错误。

这是我的 Json 对象:

{
  { "a": "q"
    "b": "w",
    "c": "t"
  },
  { "a": "x"
    "b": "y",
    "c": "z"
  }
}

这就是我需要的:

  [  
    {
     { "a": "q"
       "b": "w",
       "c": "t"
     },
     { "a": "x"
       "b": "y",
       "c": "z"
     }
   }
 ]

【问题讨论】:

    标签: json api testing bdd karate


    【解决方案1】:

    试试这个方法,使用嵌入式表达式:https://github.com/intuit/karate#embedded-expressions

    * def foo = { a: 1 }
    * def list = [ '#(foo)' ]
    * match each list == foo
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-07
      • 1970-01-01
      • 2012-07-21
      相关资源
      最近更新 更多