JSONPATH - MULTIPLE RECORD SYNTAX IN GROOVYSCRIPT?
Hi,
I always struggle with JSONPATH relative to XPATH and this is another instance.
I have an assertion in my groovy script with the following syntax for a single record in the resultset - just to clarify - the total attribute within the data node has a value of 'Rich' (JSONPATH generated by readyAPI! would generate $[data][Name])
assert object.data.Name == 'Rich'
BUT - how do I represent multiplicity for multiple records in my resultset?
i.e. if I had 2 records in my result set - so there are 2 'Name' attributes in the data node - the JSONPATH to the individual Name attributes is as follows:
$['data'][0]['Name'] $['data'][1]['Name']
The JSONPATH notation in my groovy differs - does anyone know how to create a specific assertion on each of the above 'Name' attributes?
I tried
assert object.data.0.Name == 'Rich'
and
assert object.data.[0].Name == 'Rich'
As always? I appreciate all/any guidance/help/education anyone's willing to impart! :)
Cheers,
richie
- Are you expecting result is list of names?
If so,
assert object.data.Name == ['name1', 'name2'...]
Does it help?