Brock Brown
Brock Brown

Reputation: 23

Karate json key list variable assignment

New to Karate, and JSON, for that matter, but I've got a variable like:

response {
  entries {
    products [
      {
        names [
          "Peter Parker",
          "Tony Stark",
          "Captain America"
        ]
      },
      {
        names [
          "Thomas Tinker",
          "Jimmy Johnson",
          "Mama Martha"
        ]
      }
    ]
  }
}

match each response.entries.products[*].names returns a list like:

["Peter Parker","Tony Stark","Captain America","Thomas Tinker","Jimmy Johnson","Mama Martha"]

But I'd like to assign that output to a variable, such as:

* def variable = response.entries.products[*].names

that would hold a similar value. When I use the above line, I get the following error:

Expected an operand but found *

Is it possible to achieve that, or something similar? If so, how?

Thanks!

Upvotes: 2

Views: 215

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Yes, there is syntax for that:

* def variable = $response.entries.products[*].names

Read the docs: https://github.com/intuit/karate#get

Upvotes: 1

Related Questions