how can i get the sample id of a product for which status is 'available' from the json response using groovy script
[ { "sampleId": "17", "partNumber": "83729219", "sampleName": "Peter", "shortDescription": "Peter", "description": "Peter", "productUrl": " https://www.alwaysdis ", "sampleImage": " http://sit1.author.gillette ", "sku": null, "categoryId": 4, "parentSampleId": null, "locale": "en-GB", "variantName": "Pads Plus", "stockCount": 0, "noOfOrderPerCategory": 0, "noOfOrderPerSample": 0, "status": "NOT_AVAILABLE", "variants": [] }, { "sampleId": "27", "partNumber": "83729568", "sampleName": "ALWAYS DISCREET Incontinence Pants Normal", "shortDescription": null, "description": "\\n
how can i get the sample id of a product for which status is 'available' from the json response using groovy script.
You can use JSONSlurper
to parse the String and then just use a Closure
to filter the data, like this:
def slurper = new groovy.json.JsonSlurper()
def result = slurper.parseText(jsonData)
def availableSamples = result.findAll{it.status == 'AVAILABLE'}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.