0
{
"shipToAddress":{
    "country":"SE",
    "zipCode":"AB101AA",
    "emailAddress":"abc@gmail.com"
    },
"deliveryArrangementsId":"DA100000011",
"itemLines":{
    "itemLine":[{
        "unitWeight":"2.3",
        "bundleParentId":"",
        "itemType":"ART",
        "requiredQty":"10.0",
        "unitOfMeasure":"Piece",
        "unitVolume":"1.3",
        "id":"IL1",
        "itemNo":"0000001",
        "volumeUnitOfMeasure":"CUMETER",
        "weightUnitOfMeasure":"KG"
        }]
    },
"businessUnit":{"code":"856","type":"STO"},
"serviceTypes":{"serviceType":[
    {
        "id":"HOME_DELIVERY",
        "possibleSolutions":{
            "possibleSolution":[
                {
                    "service":"STANDARD",
                    "unavailableLines":{
                        "unavailableLine":[
                            {
                                "unavailableQty":"10.0",
                                "itemLineId":"4",
                                "unavailableReasonCode":"NOT_ENOUGH_PRODUCT_CHOICES"
                            },
                            {
                                "unavailableQty":"5.0",
                                "itemLineId":"3",
                                "unavailableReasonCode":"NOT_ENOUGH_PRODUCT_CHOICES"
                            }
                        ]
                    },
                    "id":"HD1",
                    "deliveries":{
                        "delivery":[
                            {
                                "serviceItemId":"SGR40400001",
                                "deliveryId":"1",
                                "unitOfMeasure":"ORDERS"
                            },
                            {
                                "serviceItemId":"SGR40400003",
                                "deliveryId":"2",
                                "unitOfMeasure":"ORDERS"
                            },
                            {
                                "serviceItemId":"SGR40400001",
                                "deliveryId":"3",
                                "unitOfMeasure":"ORDERS"
                            }
                        ]
                    },
                    "earliestShipDate":"2018-12-03T07:00:00.000Z"
                },
                {
                    "service":"CURBSIDE",
                    "unavailableLines":{
                        "unavailableLine":[
                            {
                                "unavailableQty":"10.0",
                                "itemLineId":"4",
                                "unavailableReasonCode":"NOT_ENOUGH_PRODUCT_CHOICES"
                            },
                            {
                                "unavailableQty":"5.0",
                                "itemLineId":"3",
                                "unavailableReasonCode":"NOT_ENOUGH_PRODUCT_CHOICES"
                            }
                        ]
                    },
                    "id":"HD2",
                    "deliveries":{
                        "delivery":[
                            {
                                "serviceItemId":"SGR40400002",
                                "deliveryId":"1",
                                "unitOfMeasure":"ORDERS"
                            },
                            {
                                "serviceItemId":"SGR40400003",
                                "deliveryId":"2",
                                "unitOfMeasure":"ORDERS"
                            },
                            {
                                "serviceItemId":"SGR40400002",
                                "deliveryId":"3",
                                "unitOfMeasure":"ORDERS"
                            }
                        ]
                    },
                    "earliestShipDate":"2018-12-03T07:00:00.000Z"
                },
                {
                    "service":"EXPRESS",
                    "id":"HD3",
                    "deliveries":{
                        "delivery":{
                            "serviceItemId":"SGR40400005",
                            "deliveryId":"4",
                            "unitOfMeasure":"ORDERS"
                        }
                    },
                    "earliestShipDate":"2018-12-01T07:00:00.000Z"
                }
            ]
        },
        "possibleDeliveries":{
            "possibleDelivery":[
                {
                    "shipNode":"CDC.269",
                    "id":"1",
                    "deliveryAssocations":{
                        "deliveryAssocation":[
                            {
                                "itemQty":"10.0",
                                "itemLineId":"1"
                            },
                            {
                                "itemQty":"10.0",
                                "itemLineId":"2"
                            }
                        ]
                    }
                },
                {
                    "shipNode":"CDC.027",
                    "id":"2",
                    "deliveryAssocations":{
                        "deliveryAssocation":[
                            {
                                "itemQty":"10.0",
                                "itemLineId":"5"
                            }
                        ]
                    }
                },
                {
                    "shipNode":"CDC.030",
                    "id":"3",
                    "deliveryAssocations":{
                        "deliveryAssocation":[
                            {
                                "itemQty":"5.0",
                                "itemLineId":"3"
                            }
                        ]
                    }
                },
                {
                    "shipNode":"STO.896",
                    "id":"4",
                    "deliveryAssocations":{
                        "deliveryAssocation":[
                            {
                                "itemQty":"10.0",
                                "itemLineId":"1"
                            },
                            {
                                "itemQty":"10.0",
                                "itemLineId":"2"
                            },
                            {
                                "itemQty":"10.0",
                                "itemLineId":"3"
                            },
                            {
                                "itemQty":"10.0",
                                "itemLineId":"4"
                            },
                            {
                                "itemQty":"10.0","itemLineId":"5"
                            }
                        ]
                    }
                }
            ]
        }
    },
    {
        "id":"CLICK_COLLECT",
        "possibleSolutions":{
            "possibleSolution":[
                {
                    "service":"STANDARD",
                    "unavailableLines":{
                        "unavailableLine":[
                            {
                                "unavailableQty":"10.0",
                                "itemLineId":"1",
                                "unavailableReasonCode":"NOT_ENOUGH_PRODUCT_CHOICES"
                            }
                        ]
                    },
                    "id":"CC1",
                    "deliveries":{
                        "delivery":[
                        {
                            "serviceItemId":"SGR60000851",
                            "deliveryId":"1",
                            "pickupPoints":{
                                "pickupPoint":[
                                    {
                                        "country":"GB",
                                        "identifier":"PUP1004 Oxford 4 TSP B@IKEA_TSP_B_GB",
                                        "zipCode":"SN1 4BJ",
                                        "openingHoursThuTime":"10:00-21:00",
                                        "distance":"15.91",
                                        "city":"Swindon",
                                        "openingHoursSatTime":"10:00-21:00",
                                        "openingHoursWedTime":"10:00-21:00",
                                        "openingHoursFriTime":"10:00-21:00",
                                        "name":"ICA Maxi Helsingborg",
                                        "openingHoursTueTime":"10:00-21:00",
                                        "addressLine1":"Devizes Road",
                                        "openingHoursSunTime":"11:00-18:00",
                                        "addressLine2":"Devizes",
                                        "openingHoursMonTime":"10:00-21:00",
                                        "addressLine3":"Near Center",
                                        "id":"PUP1004 Oxford 4 TSP B",
                                        "state":"GB",
                                        "addressLine4":"1-3",
                                        "lsc":"LSC.1004"
                                    },
                                    {
                                        "country":"GB",
                                        "identifier":"PUP1043 Oxford 4 TSP B@IKEA_TSP_B_GB",
                                        "zipCode":"SN1 4BK",
                                        "openingHoursThuTime":"10:00-21:00",
                                        "distance":"18.01",
                                        "city":"Swindon",
                                        "openingHoursSatTime":"10:00-21:00",
                                        "openingHoursWedTime":"10:00-21:00",
                                        "openingHoursFriTime":"10:00-21:00",
                                        "name":"PostNord",
                                        "openingHoursTueTime":"10:00-21:00",
                                        "addressLine1":"Devizes Road",
                                        "openingHoursSunTime":"11:00-18:00",
                                        "addressLine2":"Devizes",
                                        "openingHoursMonTime":"10:00-21:00",
                                        "addressLine3":"Near Center",
                                        "id":"PUP1043 Oxford 4 TSP B",
                                        "state":"GB",
                                        "addressLine4":"1-3","lsc":"LSC.1043"
                                    }
                                ]
                            }

In the above response I need to extract the below part:

[{"id":"HOME_DELIVERY",
    "possibleSolutions":{
    "possibleSolution":[{
        "service":"STANDARD",
        "unavailableLines":{
            "unavailableLine":[{
                "unavailableQty":"10.0",
                "itemLineId":"4",
                "unavailableReasonCode":"NOT_ENOUGH_PRODUCT_CHOICES"
            },
                {"unavailableQty":"5.0",
                "itemLineId":"3",
                "unavailableReasonCode":"NOT_ENOUGH_PRODUCT_CHOICES"}]}

Kindly help me to resolve this

closed as off-topic by Bharat Mane, Ray Oei, alecxe Feb 28 at 13:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development unrelated to testing are off-topic here, but can be asked on Stack Overflow." – Bharat Mane, alecxe
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    jsonformatter.curiousconcept.com Try a beautiflier it will help you a lot! :) – Decypher Feb 28 at 7:31
  • This part seems to be quite big to be effectively extracted using regular expression. What is your goal? why do you need that part? What are you going to do with that part? Is there any regexp you have already tried? – Alexey R. Feb 28 at 10:04
1

Both your JSON entities are invalid therefore I'm afraid no one will be able to help. To give you some direction you can use Json Path to filter out "interesting" parts of the source JSON and JsonBuilder to produce the new one.

  1. Add JSR223 PostProcessor as a child of the request which returns the "bigger" JSON
  2. Put the following code into "Script" area:

    def filter = com.jayway.jsonpath.JsonPath.read(prev.getResponseDataAsString(), '$..serviceType[?(@.id == \'HOME_DELIVERY\')].possibleSolutions.possibleSolution[?(@.service == \'STANDARD\')].unavailableLines')
    def newJson = new groovy.json.JsonBuilder(filter).toPrettyString()
    log.info(newJson)
    vars.put('newJson', newJson)
    

    enter image description here

  3. That's it, you should now be able to refer extracted JSON as ${newJson} where required

    enter image description here

References:

Not the answer you're looking for? Browse other questions tagged or ask your own question.