jeudi 12 juillet 2018

how to apply if-else for a complex JSON array

here is the JSON sample that I have [

{

    "index": 0,

    "object": {

        "uri": "entities/oAFpSUX",

        "type": "configuration/entityTypes/Pet",

        "createdBy": "abc@xyz.com",

        "createdTime": 1531431176965,

        "updatedBy": "abc@xyz.com",

        "updatedTime": 1531431177691,

        "attributes": {

            "Weight": [

                {

                    "label": "5 lbs",

                    "value": {

                        "PetWeightMeasurement": [

                            {

                                "ov": true,

                                "value": "5",

                            }

                        ],

                        "PetWeightUOM": [

                            {

                                "ov": true,

                                "value": "lbs",

                                "lookupCode": "lbs",

                            }

                        ]

                    },

                    "ov": true,

                    "uri": "entities/oAFpSUX/attributes/Weight/1AeFvD8Kj"

                }

            ],

            "Identifiers": [

                {

                    "label": "5155445576",

                    "value": {

                        "Type": [

                            {

                                "ov": false,

                                "value": "CRMO_Pet_Id",

                            }

                        ],

                        "ID": [

                            {

                                "ov": true,

                                "value": "5155445576",

                            }

                        ]

                    },

                    "ov": true,

                    "uri": "entities/oAFpSUX/attributes/Identifiers/1AeFvCrHh"

                }

            ],

            "Vaccination": [

                {

                    "label": "Bordatella - 2018-10-26",

                    "value": {

                        "Type": [

                            {

                                "type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/Type",

                                "ov": true,

                                "value": "Bordatella",

                                "lookupCode": "4",

                                "lookupRawValue": "Bordatella",

                                "lookupAttributes": [

                                    {

                                        "name": "Sort Order",

                                        "value": "3"

                                    }

                                ],

                                "uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr/Type/1AeFvA2X7"

                            }

                        ],

                        "ExpirationDate": [

                            {

                                "type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/ExpirationDate",

                                "ov": true,

                                "value": "2018-10-26",

                                "uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr/ExpirationDate/1AeFvA6nN"

                            }

                        ]

                    },

                    "ov": true,

                    "uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9yGr"

                },

                {

                    "label": "Distemper - 2018-10-25",

                    "value": {

                        "Type": [

                            {

                                "type": "configuration/entityTypes/Pet/attributes/Vaccination/attributes/Type",

                                "ov": true,

                                "value": "Distemper",

                                "lookupAttributes": [

                                    {

                                        "name": "Sort Order",

                                        "value": "4"

                                    }

                                ],

                                "uri": "entities/oAFpSUX/attributes/Vaccination/1AeFv9YhJ/Type/1AeFv9cxZ"

                            }

                        ],....

My question: I was able to get the value of "$..Vaccination..value.Type..value" as "Bordatella" so that works fine. However what I now want is that if the value is 'Bordatella' then I want to extract the "value" under "ExpirationDate". Can someone please help me how I can extract that "value" under "ExpirationDate" ? I am not sure if I need to do that with some custom Groovy code of using jmeter's if controller. Any help would be greatly appreciated!

Thanks.

Aucun commentaire:

Enregistrer un commentaire