ColdDevil
ColdDevil

Reputation: 23

Access JSONPath firstLevel sons

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"
]

Upvotes: 1

Views: 46

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

That's pretty simple, here you go:

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

Upvotes: 2

Related Questions