Ask a Question

JSONPATH - MULTIPLE RECORD SYNTAX IN GROOVYSCRIPT?

SOLVED
richie
Community Hero

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

 

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
3 REPLIES 3
nmrao
Community Hero

Are you expecting result is list of names?

If so,

assert object.data.Name == ['name1', 'name2'...]

Does it help?


Regards,
Rao.
richie
Community Hero

aaah!

 

So you're saying rather than have individual assertions that definitely describe their location in the response - just have one assertion with the expected results being an array of values?

 

hahahaha! that'll do!

 

Thanks man!

 

richie!

 

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
nmrao
Community Hero

Exactly. It is completely ok to have single assertion which can handle either simple or complex checks.


Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: