1

I am making a post call and after post call the object goes into array at random position so how can I assert for that object.without knowing it's response. message[position?].

Please suggest me what can I do.

1 Answers1

0

Use JsonPath. Here is one example: https://stackoverflow.com/a/64373344/143475

Keep in mind there are plenty of ways to extract data from JSON that ignores the exact path or position. For example:

* def response = { a: 1, b: 2, c: 3, d: { a: 1, b: 2, e: 5 } }
* def extracted = $..e
* match extracted contains 5

If you are just concerned about arrays, use contains: https://github.com/karatelabs/karate#match-contains

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • thanks Peter for the answer its working but now I am facing issue that there is a duplicate data present in the array so how can I assert exact line of array without knowing its position – Ashish Patil Oct 31 '22 at 07:00
  • @AshishPatil see if this answer helps: https://stackoverflow.com/a/68065532/143475 - if not, please ask a new question and this time PLEASE provide an example – Peter Thomas Oct 31 '22 at 07:57