Access Jsonpath第一级儿子

发布于 2025-02-10 19:25:25 字数 401 浏览 2 评论 0原文

因此,我有这个答案,除其他外,我想提取的是对其他答案进行测试。

{
  "subject": {
    "pe": {
      "total": 23,
      "passed": 2,
      "failed": 1,
    },
    "maths": {
      "total": 23,
      "passed": 19,
      "failed": 4,
    },
    "history": {
      "total": 20,
      "passed": 17,
      "failed": 3
    }
  }
}

我只能得到主题?喜欢:

{
  "pe",
  "maths",
  "history"
]

So, I have this answer I want to extract, among other things, the subjects, to test against other answers.

{
  "subject": {
    "pe": {
      "total": 23,
      "passed": 2,
      "failed": 1,
    },
    "maths": {
      "total": 23,
      "passed": 19,
      "failed": 4,
    },
    "history": {
      "total": 20,
      "passed": 17,
      "failed": 3
    }
  }
}

How do I get only the subjects?? Like:

{
  "pe",
  "maths",
  "history"
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

牵你手 2025-02-17 19:25:25

这很简单,您去这里:

* def subjects = karate.keysOf(response.subject)
* match subjects == ['pe', 'maths', 'history']

That's pretty simple, here you go:

* def subjects = karate.keysOf(response.subject)
* match subjects == ['pe', 'maths', 'history']
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文