Forum Discussion

imran9561186681's avatar
New Contributor
3 years ago

Remove brackets from property which is fetch from another response.

I have expand the response using below groovy script and set the property as well. 

def json_s = new JsonSlurper()
response = context.expand('${Order_Details#Response}')
json_response1 = json_s.parseText(response)
//response = response.replace('[]','')
testRunner.testCase.setPropertyValue("productSKU", String.valueOf(json_response1.extension_attributes.shipping_assignments.items.product_id))


Property got set as = [[5885]]

Response of Order_Details is: 
"extension_attributes": {
"shipping_assignments": [ {
"shipping": {
"address": {
"address_type": "shipping",
"method": "simpleshipping_simpleshipping",
"total": {
"base_shipping_amount": 0,
"base_shipping_discount_amount": 0,
"items": [ {
"product_id": 3245,
"base_amount_refunded": 0,
"updated_at": "2021-08-26 13:38:25",
"weight": 0.374


now, I have remove the [[  ]] from property. How can I achieve with groovy.

1 Reply

  • nmrao's avatar
    Champion Level 3

    Not sure how you are getting below while the response has the value "3245"

    Property got set as = [[5885]]

    Please try below:

    testRunner.testCase.setPropertyValue("productSKU", String.valueOf(json_response1.extension_attributes.shipping_assignments.items.product_id.flatten().first()))

    Please note that the above solution may work with given data.


    If the response has multiple products and you want specific value, then solution might differ based on the data.