Hello henil_shah,
I think just adding an element number of the array/list to the assertion will work for you. Groovy script sample below.
Regards
import groovy.json.*;
def jsonSampletxt = '''
[{
"id": "1234",
"name": "xyz",
"jsonfield1": {
"jsonfield": "xyz"
}
}]
''';
def jsonSampleobj = new JsonSlurper().parseText(jsonSampletxt);
jsonSampleobj.each { item ->
log.info 'item=' + item.toString();
};
log.info 'jsonSampleobj.size()= ' + jsonSampleobj.size();
log.info ' ';
log.info 'jsonSampleobj.id=' + jsonSampleobj.id;
log.info 'jsonSampleobj.id[0]=' + jsonSampleobj.id[0];
log.info 'jsonSampleobj.name=' + jsonSampleobj.name;
log.info 'jsonSampleobj.name[0]=' + jsonSampleobj.name[0];
assert jsonSampleobj.id[0] == '1234', "Element 0 of .id Array/List should be equal to '1234'";
assert jsonSampleobj.name[0] == 'xyz', "Element 0 of .name Array/List should be equal to 'xyz'";
log.info 'Test Step "' + testRunner.runContext.currentStep.name + '" done...';