Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.
How can I Assert the number of child elements in JSON
Comments
-
Use an Occurrence assertion (under Structure assertions).
0 -
Using Occurrence assertion I can only asset the elements returned.
Here I just want the assertion that there are 20 elements returned in my parent element. I do not need individual elements asserted.
0 -
Do we know how we can assert only the number of elements returned back
0 -
Let's say I have the following JSON:
{ "foo" : { "a" : 1, "b" : 2 } }
I want to verify that the element "foo" has two elements, but I don't care what they are. Then I create an Occurrence Assertion with the XPath /root/foo/* that verifies that there are 2 elements. The wildcard * is how I can select multiple child elements regardless of what they are.
0 -
It works, thanks!
0