0

I need to get count value based on matching critera using REST Assured Jsonpath

I tried the following but its not working :

response().jsonPath().getString("{it.B == '456'}.B1.size()")

JSON :

[{ "A": "123", "A1": [{ "A11": "A111" }, { "A12": "A112" }, { "A13": "A113" }] },
{ "B": "456", "A1": [{ "B11": "B111" }, { "B12": "B112" }, { "B13": "B113" }, { "B14": "B114" }, { "B15": "B115" }] },
{ "C": "456", "A1": [{ "C11": "C111" }, { "C12": "C112" }, { "C13": "C113" }, { "C14": "C114" }, { "C15": "C115" }, { "C16": "C116" }] }
]
whoami - fakeFaceTrueSoul
  • 17,086
  • 6
  • 32
  • 46
novice
  • 43
  • 11
  • What do you mean by "not working"? Does it throw an error or the returned data is not what you expect? Please update your question with that information. – luis.parravicini Oct 03 '19 at 20:33
  • It was throwing an error . I basically dont know how to use this syntax – novice Oct 03 '19 at 20:50

1 Answers1

0

Please try the below, it will return 456

response().jsonPath().getString("$.[1].B")

whoami - fakeFaceTrueSoul
  • 17,086
  • 6
  • 32
  • 46
  • thanks for the response @KnowledgeSeeker001 . My JSON was incorrect in the question . I have updated it . I need to get the count of "A1" depending on the matching criteria which could be "A" or "B" or "C" value . If filter is A= 123, it should return the size of A1 as 3 . If its B=456, then it should return the size of A1 as 5 – novice Oct 03 '19 at 18:36