1

I am using DBUtils' readRows() method in Karate and receiving a response in the form of a list of maps which I save as a json variable called response. The data looks like this:

[
      {
        "ID": "001"
      },
      {
        "ID": "002"
      },
      {
        "ID": "003"
      }
]

The assertion works with

* match response[*].ID == ["001", "002", "003"]

but it doesn't print anything for

* print response[*].ID

I was expecting it would print the three id's ["001", "002", "003"]. Any idea why its not printing anything?

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
mitymouse
  • 33
  • 2
  • @PeterThomas the answer you gave in my other question didn't help, just like the answer for this question – mitymouse Jul 13 '20 at 05:38
  • this question has nothing to do with DBUtils BTW which confused me. hint: `print` supports only JS. when you see a `*` or `..` it is JsonPath. read the docs: https://github.com/intuit/karate#get – Peter Thomas Jul 13 '20 at 05:53
  • @mitymouse store the response[*].ID in a variable and print the variable. – Neodawn Jul 13 '20 at 10:10
  • @PeterThomas thanks, that helped. Can you not associate my question as you have done above, since it has nothing to do with that? @Neodawn thanks for the tip. Actually, I tried that and it didn't work. You have to store it using what Peter mentioned in the link above (github.com/intuit/karate#get). So for the example above, first `* def output = $response[*].ID` and then `* print output`. If you try to print it directly like `* print $response[*].ID` it won't work. – mitymouse Jul 13 '20 at 14:02
  • @mitymouse done. now you know what to do ;) – Peter Thomas Jul 13 '20 at 15:25

1 Answers1

1

Do this:

* def output = $response[*].ID
* print output
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248