Compare a GUID attribute value from 2 different json responses?
Hey,
I don't know if I'm being an idiot - whether my mind's gone blank and there's a GUI way of doing this or whether I have to rely on groovy.
Anyway - I have 2 GET requests and these generate 2 .json responses
Within each of these 2 GET requests' responses, a unique GUID value is returned (format like e6de8a88-cad1-e611-80d2-3863bb361018)
I need to compare the GUID values from each of these and assert that they are identical
The format of the 1st response is as follows:
[ { "@odata.etag" : "W/\"4815016\"", "whatevs1" : 1, "whatevs2" : 1, "GUID" : "5ae7c359-e148-4ea2-a4b7-d5500aebe185", } ] jsonpath to GUID in response == $[0]['GUID']
The format of the 2nd response is as follows:
{ "@odata.context" : "https://whatevs.crm4.dynamics.com/api/data/v9.0/$metadata#GUID(GUID)", "value" : [ { "@odata.etag" : "W/\"1569419\"", "GUID" : "5ae7c359-e148-4ea2-a4b7-d5500aebe185" } ] } jsonpath to GUID in second response: $['value'][0]['GUID']
Now I've began putting together the following groovy to compare and assert the two GUID values
import groovy.json.JsonSlurper
def Response1 = context.expand( '${#GetDonorID#Response#://$['value'][0]['GUID']}' ).toString()
GetDonorID = new JsonSlurper().parseText Response1
def Response2 = context.expand( '${#GetGUID#Response#://$[0]['GUID']}' ).toString()
GetGUID = new JsonSlurper().parseText Response2
assert GetDonorID == GetGUID
I'm getting multiple compilation errors - which I'm assuming is cos I tried adding in the jsonpath to my context expand line - but I've seen this done using xpath using XMLSlurper so I thought this would work using the JsonSlurper.
Can anyone advise where I'm going wrong with this?
I was thinking I could pass both options to a Properties step and use 3 lines of groovy to compare and assert the 2 properties but I already know I can get the properties approach to work and I'm not going to expand my education doing this approach - hence the reason I'm trying this way instead!
Many thanks to any hints/tips/guidance etc.
richie