cancel
Showing results for 
Search instead for 
Did you mean: 

JSONPATH - MULTIPLE RECORD SYNTAX IN GROOVYSCRIPT?

SOLVED
Highlighted
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
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: JSONPATH - MULTIPLE RECORD SYNTAX IN GROOVYSCRIPT?

Are you expecting result is list of names?

If so,

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

Does it help?


Regards,
Rao.

View solution in original post

3 REPLIES 3
Highlighted
Community Hero

Re: JSONPATH - MULTIPLE RECORD SYNTAX IN GROOVYSCRIPT?

Are you expecting result is list of names?

If so,

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

Does it help?


Regards,
Rao.

View solution in original post

Highlighted
Community Hero

Re: JSONPATH - MULTIPLE RECORD SYNTAX IN GROOVYSCRIPT?

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
Highlighted
Community Hero

Re: JSONPATH - MULTIPLE RECORD SYNTAX IN GROOVYSCRIPT?

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


Regards,
Rao.
New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Compete with community members in the TechCorner Challenge and get into the Leaderboard!

Rank Participant Points Earned
1 msiadak 9
2 nmrao 6
3 HimanshuTayal 3
Top Kudoed Authors