JsonPath Conditions from another array | JMETER - jmeter

Using JSONPath I'm trying to fetch pools > id > options > id
based on this condition:
componentGroups > id > poolId = pools > id
"poolId": "cb720883-04f1-4be4-a416-2f0c75230768", = "id": "cb720883-04f1-4be4-a416-2f0c75230768",
I mean one of those IDs from the payload below:
Example 1:
for "poolId": "cb720883-04f1-4be4-a416-2f0c75230768", pools > id should be:
"id": "355548b5-b032-44f5-bf91-acfe987be3aa",
"id": "178709f3-f47d-4a6f-9aa1-f27958c628ea",
"id": "b0a227b0-2bf8-47cc-8422-5114edfb5c41",
"id": "ee8e2b49-7539-4ddd-90a4-6745b1385733",
Example 2:
for "poolId": "fc2ab5c-c709-4b1d-81a7-e61a8d120d8d", pools > id should be:
"id": "cf85f8ca-7686-4585-b154-2e069e7bf976",
"id": "b0f6c744-af0a-4395-a2d5-bfaf39aeeab5",
the JSON extractor I use:
$.data[?(#.productId=='1231a29f0c3-9180-4cd7-a5c7-282f6689c31a')].pools..options[?(#.componentGroups..poolId = .pools.*.id)].id
{
"error": null,
"data": [
{
"id": "d8af6a50-1bf4-4792-97ea-f9c819c60f8e",
"productId": "1231a29f0c3-9180-4cd7-a5c7-282f6689c31a",
"productName": "Acme One Hundred Percent",
"pools": [
{
"id": "cb720883-04f1-4be4-a416-2f0c75230768",
"options": [
{
"id": "355548b5-b032-44f5-bf91-acfe987be3aa",
"optionAmount": 1,
"optionIndex": 0,
"optionName": "$1",
"audio": null,
"image": "https://123./1-dollar-ball.png"
},
{
"id": "178709f3-f47d-4a6f-9aa1-f27958c628ea",
"optionAmount": 5,
"optionIndex": 1,
"optionName": "$5",
"audio": null,
"image": "https://123/5-dollar-ball.png"
},
{
"id": "b0a227b0-2bf8-47cc-8422-5114edfb5c41",
"optionAmount": 10,
"optionIndex": 2,
"optionName": "$10",
"audio": null,
"image": "https://123/10-dollar-ball.png"
},
{
"id": "ee8e2b49-7539-4ddd-90a4-6745b1385733",
"optionAmount": 20,
"optionIndex": 3,
"optionName": "$20",
"audio": null,
"image": "https://123/20-dollar-ball.png"
}
],
"poolName": "Panel Amounts",
"audio": null,
"image": null
},
{
"id": "2f1403cb-df3e-4fbf-b594-352f76943895",
"options": [
{
"id": "a5dc21e7-cc4e-4e93-b74f-1f4b19f322ef",
"optionAmount": 0,
"optionIndex": 0,
"optionName": "Heads",
"audio": null,
"image": "https://123/OneHundredPercent/LibertyBellCoin.png"
}
],
"poolName": "Heads",
"audio": null,
"image": null
}
],
"componentGroups": [
{
"id": "126140ac-1cfa-40a3-9ab7-1a84469ab0db",
"poolId": "cb720883-04f1-4be4-a416-2f0c75230768",
"components": [
{
"id": "8291365c-df9f-4d7b-8f34-be0b500065ee",
"componentConsumerSelectionType": 2,
"componentName": "Panel Amount",
"audio": null,
"image": null
}
],
"componentGroupName": "Panel Amount Components",
"audio": null,
"image": null
},
{
"id": "03ed0e60-8fba-4e01-83c2-ce960bf5e889",
"poolId": "2f1403cb-df3e-4fbf-b594-352f76943895",
"components": [
{
"id": "3f4b1a61-5d80-4b78-8c20-9f2b92022cf4",
"componentConsumerSelectionType": 1,
"componentName": "Heads",
"audio": null,
"image": null
}
],
"componentGroupName": "Heads Components",
"audio": null,
"image": null
}
]
},
{
"id": "b203c9bc-1a7e-4fe5-9b5b-d8021ea118c6",
"productId": "123557a97a5-ef93-46b7-868c-4f26439fbcb9",
"productName": "Acme Pick 3",
"pools": [
{
"id": "efc2ab5c-c709-4b1d-81a7-e61a8d120d8d",
"options": [
{
"id": "cf85f8ca-7686-4585-b154-2e069e7bf976",
"optionAmount": 0.5,
"optionIndex": 0,
"optionName": "$.50",
"audio": null,
"image": "https://123/01.png"
},
{
"id": "b0f6c744-af0a-4395-a2d5-bfaf39aeeab5",
"optionAmount": 1,
"optionIndex": 1,
"optionName": "$1",
"audio": null,
"image": "https://123/01.png"
}
],
"poolName": "Panel Amounts",
"audio": null,
"image": null
},
{
"id": "60b8910b-baa7-4776-bb7a-05f277887a11",
"options": [
{
"id": "d51485a5-1cb4-4aca-8ad9-551ac0bddce3",
"optionAmount": 0,
"optionIndex": 0,
"optionName": "Exact Order",
"audio": null,
"image": "https://123/tilestraight.png"
},
{
"id": "4ed3eaa0-7b58-47db-8072-bbe78f0e40cf",
"optionAmount": 0,
"optionIndex": 1,
"optionName": "Any Order",
"audio": null,
"image": "https://123/tilebox.png"
},
{
"id": "46571384-8bea-404b-8aa1-c0965fa0bed1",
"optionAmount": 0,
"optionIndex": 2,
"optionName": "50/50",
"audio": null,
"image": "https://123/tilefiftyfifty.png"
},
{
"id": "325d52e8-ed3f-4a69-8f09-8e49a53608dd",
"optionAmount": 0,
"optionIndex": 3,
"optionName": "Front Pair",
"audio": null,
"image": "https://123/tilefrontpair.png"
},
{
"id": "5960a4af-0b74-4c2b-b8a4-2dc4033e96a2",
"optionAmount": 0,
"optionIndex": 4,
"optionName": "Split Pair",
"audio": null,
"image": "https://123/tilesplitpair.png"
},
{
"id": "c2a817ca-1bd8-4b5b-8f6f-e12f3286ea54",
"optionAmount": 0,
"optionIndex": 5,
"optionName": "Back Pair",
"audio": null,
"image": "https://123/tilebackpair.png"
}
],
"poolName": "Play Types",
"audio": null,
"image": null
},
{
"id": "53fb7c9a-17dd-4f95-94b0-0110433404a2",
"options": [
{
"id": "fae5912c-9d4a-466b-b515-d60b3186c2e5",
"optionAmount": 0,
"optionIndex": 0,
"optionName": "0",
"audio": null,
"image": "https://123/tilegreen00.png"
},
{
"id": "42055e6a-f08a-48b4-a7c8-41b87f11ca51",
"optionAmount": 0,
"optionIndex": 1,
"optionName": "1",
"audio": null,
"image": "https://123/tilegreen01.png"
},
{
"id": "ea28a99c-6068-4d67-8e2d-c6857656b499",
"optionAmount": 0,
"optionIndex": 2,
"optionName": "2",
"audio": null,
"image": "https://123/tilegreen02.png"
},
{
"id": "bf5e29ea-a377-46ad-865d-e4585d652b13",
"optionAmount": 0,
"optionIndex": 3,
"optionName": "3",
"audio": null,
"image": "https://123/tilegreen03.png"
},
{
"id": "41c26a4b-ce86-4c28-ae5a-35c13a539fbc",
"optionAmount": 0,
"optionIndex": 4,
"optionName": "4",
"audio": null,
"image": "https://123/tilegreen04.png"
},
{
"id": "fcb34895-25b9-4e5e-8a00-652febfcd31e",
"optionAmount": 0,
"optionIndex": 5,
"optionName": "5",
"audio": null,
"image": "https://123/tilegreen05.png"
},
{
"id": "0f0cf6ef-a7b7-4d11-98c4-0ea2cfd32f39",
"optionAmount": 0,
"optionIndex": 6,
"optionName": "6",
"audio": null,
"image": "https://123/tilegreen06.png"
},
{
"id": "3db2fafd-698c-44bb-a4be-f9e43ee6248b",
"optionAmount": 0,
"optionIndex": 7,
"optionName": "7",
"audio": null,
"image": "https://123/tilegreen07.png"
},
{
"id": "25d17003-9db8-407b-b6e2-65c0c2f014a0",
"optionAmount": 0,
"optionIndex": 8,
"optionName": "8",
"audio": null,
"image": "https://123/tilegreen08.png"
},
{
"id": "37232037-ca87-4f2e-99a4-40cbfec2bf62",
"optionAmount": 0,
"optionIndex": 9,
"optionName": "9",
"audio": null,
"image": "https://123/tilegreen09.png"
}
],
"poolName": "Numbers",
"audio": null,
"image": null
}
],
"componentGroups": [
{
"id": "85ee94f1-fbcf-4392-aa08-5320abc13dcc",
"poolId": "efc2ab5c-c709-4b1d-81a7-e61a8d120d8d",
"components": [
{
"id": "a3d14456-64cb-4cae-b749-133c4b6a476a",
"componentConsumerSelectionType": 2,
"componentName": "Panel Amount",
"audio": null,
"image": null
}
],
"componentGroupName": "Panel Amount Components",
"audio": null,
"image": null
},
{
"id": "2be68fe5-2872-4631-b994-bb8e691db233",
"poolId": "60b8910b-baa7-4776-bb7a-05f277887a11",
"components": [
{
"id": "d50aeef2-4821-4247-b712-585a2ba55f81",
"componentConsumerSelectionType": 2,
"componentName": "Play Type",
"audio": null,
"image": null
}
],
"componentGroupName": "Play Type Components",
"audio": null,
"image": null
},
{
"id": "9b3433e8-48f3-4b37-bccb-e0ed5c55ffe8",
"poolId": "53fb7c9a-17dd-4f95-94b0-0110433404a2",
"components": [
{
"id": "ed6a4930-2558-414d-b47f-a3f95e719f60",
"componentConsumerSelectionType": 0,
"componentName": "Front Number",
"audio": null,
"image": null
}
],
"componentGroupName": "Front Number Components",
"audio": null,
"image": null
},
{
"id": "6ca0c5d1-0939-4603-9c0f-d6be5171a068",
"poolId": "53fb7c9a-17dd-4f95-94b0-0110433404a2",
"components": [
{
"id": "e0957685-22d8-4827-a3db-a1e2e0b5b76b",
"componentConsumerSelectionType": 0,
"componentName": "Middle Number",
"audio": null,
"image": null
}
],
"componentGroupName": "Middle Number Components",
"audio": null,
"image": null
},
{
"id": "e2ed942b-98e2-4d91-a500-ab5884acf66f",
"poolId": "53fb7c9a-17dd-4f95-94b0-0110433404a2",
"components": [
{
"id": "98b3c77a-bb25-4a45-a2ca-c90a79c75ecb",
"componentConsumerSelectionType": 0,
"componentName": "Back Number",
"audio": null,
"image": null
}
],
"componentGroupName": "Back Number Components",
"audio": null,
"image": null
}
]
}
]
}

Hard to follow what you want. Here is my attempt:
$.data[?(#.productId=='1231a29f0c3-9180-4cd7-a5c7-282f6689c31a')].pools.[*]
or, dig futher:
$.data[?(#.productId=='1231a29f0c3-9180-4cd7-a5c7-282f6689c31a')].pools.[].options[].id
Make your JSON path in two steps, perhaps. Two variables. Building-blocks.
Minor issues:
you have "=" instead of "==", see your "#.componentGroups..poolId = .pools.*.id"
careful with your path; you are, at one point, in componentGroups but expecting to be in pools

I think you need to go for 2 JSON Extractors:
Get all pool ids for the project you want:
$.data[?(#.productId=='1231a29f0c3-9180-4cd7-a5c7-282f6689c31a')].pools.*.id
it will give you a random pool id as ${pool_id} JMeter Variable
Then you will be able to get the ids like:
$.data.*.pools.*[?(#.id == '${pool_id}')].options.*.id
and this way you will get all pool ids:
You can see all the JMeter Variables with all their respective values using Debug Sampler and View Results Tree listener combination.

Related

JSONPath | JMeter | Condition fetch

Using JSONPath I'm trying to fetch channels > "id": "6af38171-867c-414f-a128-6668fc66cd20" based on provided productId from different request
Example 1: for "productId": "3211a29f0c3-9180-4cd7-a5c7-282f6689c31a", channel id should be "id": "29b13081-760a-4451-81d8-25f0944b3658",
Example 2: for "productId": "321557a97a5-ef93-46b7-868c-4f26439fbcb9", channel id should be "id": "6af38171-867c-414f-a128-6668fc66cd20",
Example 3: for "productId": "321ecc29f29-bc03-41d7-b107-db3be8103216", channel id should be "id": "293e31b4-8ebb-40af-8015-44b1a37ba84f",
productId picked randomly from the previous request
$..[?(#.promotionRule.promotionProducts[0].productId=="ecc29f29-bc03-41d7-b107-db3be8103216" )].id which is coming as paramter $..[?(#.promotionRule.promotionProducts[0].productId=="${je_productId}" )].id
Payload
{
"error": null,
"data": [
{
"id": "c0c18687-26cc-48da-b60a-d386279d1c3e",
"channels": [
{
"id": "29b13081-760a-4451-81d8-25f0944b3658",
"promotionRule": {
"id": "18f84232-7350-4f9f-8037-7e92eebbc4d4",
"promotionProducts": [
{
"id": "2d755bfe-8b8f-4b2a-9bf4-e8e626975b51",
"productId": "3211a29f0c3-9180-4cd7-a5c7-282f6689c31a",
"instanceCountMin": 0,
"instanceCountMax": 0,
"promotionProductRules": [
{
"componentConstraints": [
{
"description": "Panel Amount",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 2,
"componentId": "8291365c-df9f-4d7b-8f34-be0b500065ee",
"options": null
}
],
"canBeCombined": false,
"priority": 0,
"promotionRecurrence": null,
"extensions": {},
"externalId": null,
"sponsorshipAppliesToEntities": [],
"createdOn": "2022-03-25T18:37:15.5161071+00:00",
"updatedOn": null,
"deletedOn": null,
"releaseOn": null,
"expireOn": null,
"expiredOn": null,
"currency": "USD",
"ruleDescription": null,
"ruleName": null,
"simulationTypes": 0,
"value": 0.0
}
]
}
],
"maxDistributionCount": null,
"selectablePromotionsMin": 1,
"selectablePromotionsMax": 1,
"canBeCombined": false,
"priority": 0,
"promotionRecurrence": null,
"extensions": {},
"externalId": null,
"sponsorshipAppliesToEntities": [],
"createdOn": "2022-03-25T18:37:15.5152919+00:00",
"updatedOn": null,
"deletedOn": null,
"releaseOn": "2022-03-25T18:37:15.5168274+00:00",
"expireOn": null,
"expiredOn": null,
"currency": "USD",
"ruleDescription": null,
"ruleName": null,
"simulationTypes": 0,
"value": 0.0
},
"authorityName": null,
"currency": "USD",
"channelName": "The Islands of The Bahamas",
"channelLogo": "https://123/cdn/BahamasTourismBoard.png",
"channelLogoHD": null,
"channelAnimated": null,
"channelAnimatedHD": null,
"sortOrder": 0,
"releaseOn": null,
"expireOn": null,
"expiredOn": null,
"suspendedOn": null,
"suspendedBy": null
}
],
"priority": 0,
"brandName": null,
"channelGroupName": "100%",
"channelGroupLogo": "https://123/media/100percentlogo.png",
"channelGroupLogoHD": "https://123/media/100percentlogo.png",
"channelGroupAnimated": null,
"channelGroupAnimatedHD": null,
"releaseOn": null,
"expireOn": null,
"expiredOn": null,
"suspendedOn": null,
"suspendedBy": null
},
{
"id": "e2de2a1f-a21b-41db-82c0-a5710cf59dee",
"channels": [
{
"id": "6af38171-867c-414f-a128-6668fc66cd20",
"promotionRule": {
"id": "074eced6-9894-4313-85e2-2a04965fc8eb",
"promotionProducts": [
{
"id": "b93ccce2-171b-4e4e-83d7-fd77632acb4f",
"productId": "321557a97a5-ef93-46b7-868c-4f26439fbcb9",
"instanceCountMin": 0,
"instanceCountMax": 0,
"promotionProductRules": [
{
"componentConstraints": [
{
"description": "Panel Amount",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 2,
"componentId": "a3d14456-64cb-4cae-b749-133c4b6a476a",
"options": null
},
{
"description": "Play Type",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 2,
"componentId": "d50aeef2-4821-4247-b712-585a2ba55f81",
"options": null
},
{
"description": "Front Number",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 1,
"componentId": "ed6a4930-2558-414d-b47f-a3f95e719f60",
"options": null
},
{
"description": "Middle Number",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 1,
"componentId": "e0957685-22d8-4827-a3db-a1e2e0b5b76b",
"options": null
},
{
"description": "Back Number",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 1,
"componentId": "98b3c77a-bb25-4a45-a2ca-c90a79c75ecb",
"options": null
}
],
"canBeCombined": false,
"priority": 0,
"promotionRecurrence": null,
"extensions": {},
"externalId": null,
"sponsorshipAppliesToEntities": [],
"createdOn": "2022-03-25T20:17:01.7837463+00:00",
"updatedOn": null,
"deletedOn": null,
"releaseOn": null,
"expireOn": null,
"expiredOn": null,
"currency": "USD",
"ruleDescription": null,
"ruleName": null,
"simulationTypes": 0,
"value": 0.0
}
]
}
],
"maxDistributionCount": null,
"selectablePromotionsMin": 1,
"selectablePromotionsMax": 1,
"canBeCombined": false,
"priority": 0,
"promotionRecurrence": null,
"extensions": {},
"externalId": null,
"sponsorshipAppliesToEntities": [],
"createdOn": "2022-03-25T20:17:01.7829809+00:00",
"updatedOn": null,
"deletedOn": null,
"releaseOn": "2022-03-25T20:17:01.7844511+00:00",
"expireOn": null,
"expiredOn": null,
"currency": "USD",
"ruleDescription": null,
"ruleName": null,
"simulationTypes": 0,
"value": 0.0
},
"authorityName": null,
"currency": "USD",
"channelName": "The Islands of The Bahamas",
"channelLogo": "https://123/cdn/BahamasTourismBoard.png",
"channelLogoHD": "https://123/cdn/BahamasTourismBoard.png",
"channelAnimated": null,
"channelAnimatedHD": null,
"sortOrder": 0,
"releaseOn": null,
"expireOn": null,
"expiredOn": null,
"suspendedOn": null,
"suspendedBy": null
}
],
"priority": 0,
"brandName": null,
"channelGroupName": "Pick 3",
"channelGroupLogo": "https://123/brandmedia/AcmePick3.png",
"channelGroupLogoHD": "https://123/brandmedia/AcmePick3.png",
"channelGroupAnimated": null,
"channelGroupAnimatedHD": null,
"releaseOn": null,
"expireOn": null,
"expiredOn": null,
"suspendedOn": null,
"suspendedBy": null
},
{
"id": "b234c6b1-ffba-4883-ae9a-d6483b4787ab",
"channels": [
{
"id": "293e31b4-8ebb-40af-8015-44b1a37ba84f",
"promotionRule": {
"id": "863b5465-d5ab-4433-bea2-2b0d4da0cfcc",
"promotionProducts": [
{
"id": "c5031107-3995-48d0-8f26-95597531e7e4",
"productId": "321ecc29f29-bc03-41d7-b107-db3be8103216",
"instanceCountMin": 0,
"instanceCountMax": 0,
"promotionProductRules": [
{
"componentConstraints": [
{
"description": "Panel Amount",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 2,
"componentId": "db7ae266-bf79-4d63-984a-aea1aa7af460",
"options": null
},
{
"description": "White Ball - 1",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 1,
"componentId": "8b750179-6ead-425e-b5a2-ab422e72a03e",
"options": null
},
{
"description": "White Ball - 2",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 1,
"componentId": "3a87a9aa-d8c8-465a-ae35-f7d894204b13",
"options": null
},
{
"description": "White Ball - 3",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 1,
"componentId": "6b674bc4-1143-4558-8020-88872064b6d2",
"options": null
},
{
"description": "White Ball - 4",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 1,
"componentId": "0cf02fdf-c717-4ea0-a230-cb837792e7f5",
"options": null
},
{
"description": "White Ball - 5",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 1,
"componentId": "e627485b-eb3b-4afe-a20d-bed5c30ba195",
"options": null
},
{
"description": "Powerball",
"extensions": null,
"amountOfAdjustment": 0.0,
"componentConsumerSelectionType": 1,
"componentId": "e4c6e609-954a-4707-88b5-c47993fb3f82",
"options": null
}
],
"canBeCombined": false,
"priority": 0,
"promotionRecurrence": null,
"extensions": {},
"externalId": null,
"sponsorshipAppliesToEntities": [],
"createdOn": "2022-03-25T18:44:42.9594038+00:00",
"updatedOn": null,
"deletedOn": null,
"releaseOn": null,
"expireOn": null,
"expiredOn": null,
"currency": "USD",
"ruleDescription": null,
"ruleName": null,
"simulationTypes": 0,
"value": 0.0
}
]
}
],
"maxDistributionCount": null,
"selectablePromotionsMin": 1,
"selectablePromotionsMax": 1,
"canBeCombined": false,
"priority": 0,
"promotionRecurrence": null,
"extensions": {},
"externalId": null,
"sponsorshipAppliesToEntities": [],
"createdOn": "2022-03-25T18:44:42.9586017+00:00",
"updatedOn": null,
"deletedOn": null,
"releaseOn": "2022-03-25T18:44:42.9601687+00:00",
"expireOn": null,
"expiredOn": null,
"currency": "USD",
"ruleDescription": null,
"ruleName": null,
"simulationTypes": 0,
"value": 0.0
},
"authorityName": null,
"currency": "USD",
"channelName": "The Islands of The Bahamas",
"channelLogo": "https://123/cdn/BahamasTourismBoard.png",
"channelLogoHD": "https://123/cdn/BahamasTourismBoard.png",
"channelAnimated": null,
"channelAnimatedHD": null,
"sortOrder": 0,
"releaseOn": null,
"expireOn": null,
"expiredOn": null,
"suspendedOn": null,
"suspendedBy": null
}
],
"priority": 0,
"brandName": null,
"channelGroupName": "Powerball",
"channelGroupLogo": "https://123/brandmedia/PowerballLogo.png",
"channelGroupLogoHD": "https://123/brandmedia/PowerballLogo.png",
"channelGroupAnimated": null,
"channelGroupAnimatedHD": null,
"releaseOn": null,
"expireOn": null,
"expiredOn": null,
"suspendedOn": null,
"suspendedBy": null
}
]
}
"Your" $..[?(#.promotionRule.promotionProducts[0].productId=="ecc29f29-bc03-41d7-b107-db3be8103216" )].id expression works fine for me (given I add 321 to the beginning to match response data
If it doesn't work for you - check the ${je_productId} JMeter Variable value using Debug Sampler and View Results Tree listener combination
Also be aware that JMeter Variables are not being evaluated in the "JSON Path Tester" mode of the View Results Tree listener mainly because they don't exist there.

JsonPath Conditions | JMETER

Need help
trying to fetch all the 'id' for the componentConsumerSelectionType that equal 2 and exist under a particular "productId" ("123ecc29f29-bc03-41d7-b107-db3be8103216")
example 1:
"productId": "23451a29f0c3-9180-4cd7-a5c7-282f6689c31a"
"id": "8291365c-df9f-4d7b-8f34-be0b500065ee", (because "componentConsumerSelectionType": 2,)
example 2:
"productId": "123ecc29f29-bc03-41d7-b107-db3be8103216"
"id": "a3d14456-64cb-4cae-b749-133c4b6a476a", (because "componentConsumerSelectionType": 2,)
example 3:
"id": "a3d14456-64cb-4cae-b749-133c4b6a476a",(because "componentConsumerSelectionType": 2,)
example 2:
"id": "3f4b1a61-5d80-4b78-8c20-9f2b92022cf4", wrong (because "componentConsumerSelectionType": 1,)
I'm using this command to retrieve
$..[?(#.productId=="ecc29f29-bc03-41d7-b107-db3be8103216" && #.componentGroups[0].components[0].componentConsumerSelectionType == 2)].componentGroups[].components[].id
INPUT
{
"data": [
{
"id": "2344248b1b3-a7c5-4102-b45e-d0d6a4345329433d",
"productId": "23451a29f0c3-9180-4cd7-a5c7-282f6689c31a",
"productName": "100%",
"pools": [
{
"id": "cb720883-04f1-4be4-a416-2f0c75230768",
"options": [
{
"id": "355548b5-b032-44f5-bf91-acfe987be3aa",
"optionAmount": 1.0,
"optionIndex": 0,
"optionName": "$1",
"audio": null,
"image": "https://123/media/1-dollar-ball.png"
},
{
"id": "ee8e2b49-7539-4ddd-90a4-6745b1385733",
"optionAmount": 20.0,
"optionIndex": 3,
"optionName": "$20",
"audio": null,
"image": "https://123/media/20-dollar-ball.png"
}
],
"poolName": "FUNs",
"audio": null,
"image": null
},
{
"id": "2f1403cb-df3e-4fbf-b594-352f76943895",
"options": [
{
"id": "a5dc21e7-cc4e-4e93-b74f-1f4b19f322ef",
"optionAmount": 0.0,
"optionIndex": 0,
"optionName": "Heads",
"audio": null,
"image": "https://123/media/OneHundredPercent/LibertyBellCoin.png"
}
],
"poolName": "Heads",
"audio": null,
"image": null
}
],
"componentGroups": [
{
"id": "126140ac-1cfa-40a3-9ab7-1a84469ab0db",
"poolId": "cb720883-04f1-4be4-a416-2f0c75230768",
"components": [
{
"id": "8291365c-df9f-4d7b-8f34-be0b500065ee",
"componentConsumerSelectionType": 2,
"componentName": "FUN",
"audio": null,
"image": null
}
],
"componentGroupName": "FUN Components",
"audio": null,
"image": null
},
{
"id": "03ed0e60-8fba-4e01-83c2-ce960bf5e889",
"poolId": "2f1403cb-df3e-4fbf-b594-352f76943895",
"components": [
{
"id": "3f4b1a61-5d80-4b78-8c20-9f2b92022cf4",
"componentConsumerSelectionType": 1,
"componentName": "Heads",
"audio": null,
"image": null
}
],
"componentGroupName": "Heads Components",
"audio": null,
"image": null
}
]
},
{
"id": "b0793365-7212-44db-a044-12c213c020c2",
"productId": "123ecc29f29-bc03-41d7-b107-db3be8103216",
"productName": "FUN Powerball",
"pools": [
{
"id": "d929dd55-b0a8-4092-acff-570c638764f1",
"options": [
{
"id": "66ff00ab-0aba-479a-b96d-9f6011531440",
"optionAmount": 2.0,
"optionIndex": 0,
"optionName": "$2",
"audio": null,
"image": "https://123/media/2-dollar-ball.png"
},
{
"id": "9e6b0868-19b3-466d-bed2-7055efc1e993",
"optionAmount": 3.0,
"optionIndex": 0,
"optionName": "$2 + Power Play",
"audio": null,
"image": "https://123/media/2-dollar-ball+megaplier.png"
}
],
"poolName": "FUNs",
"audio": null,
"image": null
},
{
"id": "e63f9eea-4966-4c83-8764-28f8ba19f551",
"options": [
{
"id": "7cf2d659-2989-48f9-84f2-1dc117b52f7c",
"optionAmount": 0.0,
"optionIndex": 0,
"optionName": "1",
"audio": null,
"image": "https://123/media/01.png"
},
{
"id": "0f0fd71a-3482-4ca5-ba97-e0e1df2993db",
"optionAmount": 0.0,
"optionIndex": 64,
"optionName": "65",
"audio": null,
"image": "https://123/media/65.png"
},
{
"id": "916d4cba-b67e-4bfb-bf3e-08bff5e41e2f",
"optionAmount": 0.0,
"optionIndex": 65,
"optionName": "66",
"audio": null,
"image": "https://123/media/66.png"
},
{
"id": "7bf74431-bf68-4314-8e8d-2b28ca25706a",
"optionAmount": 0.0,
"optionIndex": 68,
"optionName": "69",
"audio": null,
"image": "https://123/media/69.png"
}
],
"poolName": "White Balls",
"audio": null,
"image": null
},
{
"id": "a93aa286-3e9e-47c6-a989-4cbd9b83d529",
"options": [
{
"id": "87550358-6a12-4184-9bbd-cd0aed629432",
"optionAmount": 0.0,
"optionIndex": 0,
"optionName": "1",
"audio": null,
"image": "https://123/media/01r.png"
},
{
"id": "fb049500-f6bd-4798-b330-d46b837b974d",
"optionAmount": 0.0,
"optionIndex": 23,
"optionName": "24",
"audio": null,
"image": "https://123/media/24r.png"
},
{
"id": "d721c27c-b44a-4ba6-9164-9b7971d92db8",
"optionAmount": 0.0,
"optionIndex": 24,
"optionName": "25",
"audio": null,
"image": "https://123/media/25r.png"
},
{
"id": "6a2ff192-7044-4991-91d1-38bbdd6c76a3",
"optionAmount": 0.0,
"optionIndex": 25,
"optionName": "26",
"audio": null,
"image": "https://123/media/26r.png"
}
],
"poolName": "Powerballs",
"audio": null,
"image": null
},
{
"id": "458199ef-e868-4639-b594-92c0d39422ea",
"options": [
{
"id": "d87d6298-85df-4c34-a2aa-b45de2d2d029",
"optionAmount": 0.0,
"optionIndex": 2,
"optionName": "x4",
"audio": null,
"image": "https://123/media/multiplier-x4.png"
},
{
"id": "f9c1842c-749e-4a4d-8d4f-55e3ce200fca",
"optionAmount": 0.0,
"optionIndex": 3,
"optionName": "x5",
"audio": null,
"image": "https://123/media/multiplier-x5.png"
},
{
"id": "57599727-d2f1-4249-b80f-0c4994244423",
"optionAmount": 0.0,
"optionIndex": 4,
"optionName": "x10",
"audio": null,
"image": "https://123/media/multiplier-x10.png"
}
],
"poolName": "Power Plays",
"audio": null,
"image": null
}
],
"componentGroups": [
{
"id": "b996b598-57e5-47f4-82a8-a1a54c70a6a9",
"poolId": "d929dd55-b0a8-4092-acff-570c638764f1",
"components": [
{
"id": "db7ae266-bf79-4d63-984a-aea1aa7af460",
"componentConsumerSelectionType": 2,
"componentName": "FUN",
"audio": null,
"image": null
}
],
"componentGroupName": "FUN Components",
"audio": null,
"image": null
},
{
"id": "be80677c-114b-4200-a625-badd301373a6",
"poolId": "e63f9eea-4966-4c83-8764-28f8ba19f551",
"components": [
{
"id": "8b750179-6ead-425e-b5a2-ab422e72a03e",
"componentConsumerSelectionType": 0,
"componentName": "White Ball - 1",
"audio": null,
"image": null
},
{
"id": "3a87a9aa-d8c8-465a-ae35-f7d894204b13",
"componentConsumerSelectionType": 0,
"componentName": "White Ball - 2",
"audio": null,
"image": null
},
{
"id": "6b674bc4-1143-4558-8020-88872064b6d2",
"componentConsumerSelectionType": 0,
"componentName": "White Ball - 3",
"audio": null,
"image": null
},
{
"id": "0cf02fdf-c717-4ea0-a230-cb837792e7f5",
"componentConsumerSelectionType": 0,
"componentName": "White Ball - 4",
"audio": null,
"image": null
},
{
"id": "e627485b-eb3b-4afe-a20d-bed5c30ba195",
"componentConsumerSelectionType": 0,
"componentName": "White Ball - 5",
"audio": null,
"image": null
}
],
"componentGroupName": "White Ball Components",
"audio": null,
"image": null
},
{
"id": "00757a5a-a544-4f4f-985b-60d516a999b6",
"poolId": "a93aa286-3e9e-47c6-a989-4cbd9b83d529",
"components": [
{
"id": "e4c6e609-954a-4707-88b5-c47993fb3f82",
"componentConsumerSelectionType": 0,
"componentName": "Powerball",
"audio": null,
"image": null
}
],
"componentGroupName": "Powerball Components",
"audio": null,
"image": null
},
{
"id": "eb50e66d-fb77-4d7c-845a-b9492a4c29d1",
"poolId": "458199ef-e868-4639-b594-92c0d39422ea",
"components": [
{
"id": "21a81d68-d9c1-4bea-ad7f-5656584fb37c",
"componentConsumerSelectionType": 1,
"componentName": "Power Play",
"audio": null,
"image": null
}
],
"componentGroupName": "Power Play Components",
"audio": null,
"image": null
}
]
},
{
"id": "a7bb18a0-9231-4e04-8542-4a86fe4f7f25",
"productId": "557a97a5-ef93-46b7-868c-4f26439fbcb9",
"productName": "FUN Pick 3",
"pools": [
{
"id": "efc2ab5c-c709-4b1d-81a7-e61a8d120d8d",
"options": [
{
"id": "cf85f8ca-7686-4585-b154-2e069e7bf976",
"optionAmount": 0.50,
"optionIndex": 0,
"optionName": "$.50",
"audio": null,
"image": "https://123/media/01.png"
},
{
"id": "b0f6c744-af0a-4395-a2d5-bfaf39aeeab5",
"optionAmount": 1.0,
"optionIndex": 1,
"optionName": "$1",
"audio": null,
"image": "https://123/media/01.png"
}
],
"poolName": "FUNs",
"audio": null,
"image": null
},
{
"id": "60b8910b-baa7-4776-bb7a-05f277887a11",
"options": [
{
"id": "5960a4af-0b74-4c2b-b8a4-2dc4033e96a2",
"optionAmount": 0.0,
"optionIndex": 4,
"optionName": "Split Pair",
"audio": null,
"image": "https://123/media/tilesplitpair.png"
},
{
"id": "c2a817ca-1bd8-4b5b-8f6f-e12f3286ea54",
"optionAmount": 0.0,
"optionIndex": 5,
"optionName": "Back Pair",
"audio": null,
"image": "https://123/media/tilebackpair.png"
}
],
"poolName": "Play Types",
"audio": null,
"image": null
},
{
"id": "53fb7c9a-17dd-4f95-94b0-0110433404a2",
"options": [
{
"id": "fae5912c-9d4a-466b-b515-d60b3186c2e5",
"optionAmount": 0.0,
"optionIndex": 0,
"optionName": "0",
"audio": null,
"image": "https://123/media/tilegreen00.png"
},
{
"id": "42055e6a-f08a-48b4-a7c8-41b87f11ca51",
"optionAmount": 0.0,
"optionIndex": 1,
"optionName": "1",
"audio": null,
"image": "https://123/media/tilegreen01.png"
},
{
"id": "ea28a99c-6068-4d67-8e2d-c6857656b499",
"optionAmount": 0.0,
"optionIndex": 2,
"optionName": "2",
"audio": null,
"image": "https://123/media/tilegreen02.png"
},
{
"id": "bf5e29ea-a377-46ad-865d-e4585d652b13",
"optionAmount": 0.0,
"optionIndex": 3,
"optionName": "3",
"audio": null,
"image": "https://123/media/tilegreen03.png"
},
{
"id": "41c26a4b-ce86-4c28-ae5a-35c13a539fbc",
"optionAmount": 0.0,
"optionIndex": 4,
"optionName": "4",
"audio": null,
"image": "https://123/media/tilegreen04.png"
},
{
"id": "fcb34895-25b9-4e5e-8a00-652febfcd31e",
"optionAmount": 0.0,
"optionIndex": 5,
"optionName": "5",
"audio": null,
"image": "https://123/media/tilegreen05.png"
},
{
"id": "0f0cf6ef-a7b7-4d11-98c4-0ea2cfd32f39",
"optionAmount": 0.0,
"optionIndex": 6,
"optionName": "6",
"audio": null,
"image": "https://123/media/tilegreen06.png"
},
{
"id": "3db2fafd-698c-44bb-a4be-f9e43ee6248b",
"optionAmount": 0.0,
"optionIndex": 7,
"optionName": "7",
"audio": null,
"image": "https://123/media/tilegreen07.png"
},
{
"id": "25d17003-9db8-407b-b6e2-65c0c2f014a0",
"optionAmount": 0.0,
"optionIndex": 8,
"optionName": "8",
"audio": null,
"image": "https://123/media/tilegreen08.png"
},
{
"id": "37232037-ca87-4f2e-99a4-40cbfec2bf62",
"optionAmount": 0.0,
"optionIndex": 9,
"optionName": "9",
"audio": null,
"image": "https://123/media/tilegreen09.png"
}
],
"poolName": "Numbers",
"audio": null,
"image": null
}
],
"componentGroups": [
{
"id": "85ee94f1-fbcf-4392-aa08-5320abc13dcc",
"poolId": "efc2ab5c-c709-4b1d-81a7-e61a8d120d8d",
"components": [
{
"id": "a3d14456-64cb-4cae-b749-133c4b6a476a",
"componentConsumerSelectionType": 2,
"componentName": "FUN",
"audio": null,
"image": null
}
],
"componentGroupName": "FUN Components",
"audio": null,
"image": null
},
{
"id": "2be68fe5-2872-4631-b994-bb8e691db233",
"poolId": "60b8910b-baa7-4776-bb7a-05f277887a11",
"components": [
{
"id": "d50aeef2-4821-4247-b712-585a2ba55f81",
"componentConsumerSelectionType": 2,
"componentName": "Play Type",
"audio": null,
"image": null
}
],
"componentGroupName": "Play Type Components",
"audio": null,
"image": null
},
{
"id": "9b3433e8-48f3-4b37-bccb-e0ed5c55ffe8",
"poolId": "53fb7c9a-17dd-4f95-94b0-0110433404a2",
"components": [
{
"id": "ed6a4930-2558-414d-b47f-a3f95e719f60",
"componentConsumerSelectionType": 0,
"componentName": "Front Number",
"audio": null,
"image": null
}
],
"componentGroupName": "Front Number Components",
"audio": null,
"image": null
},
{
"id": "6ca0c5d1-0939-4603-9c0f-d6be5171a068",
"poolId": "53fb7c9a-17dd-4f95-94b0-0110433404a2",
"components": [
{
"id": "e0957685-22d8-4827-a3db-a1e2e0b5b76b",
"componentConsumerSelectionType": 0,
"componentName": "Middle Number",
"audio": null,
"image": null
}
],
"componentGroupName": "Middle Number Components",
"audio": null,
"image": null
},
{
"id": "e2ed942b-98e2-4d91-a500-ab5884acf66f",
"poolId": "53fb7c9a-17dd-4f95-94b0-0110433404a2",
"components": [
{
"id": "98b3c77a-bb25-4a45-a2ca-c90a79c75ecb",
"componentConsumerSelectionType": 0,
"componentName": "Back Number",
"audio": null,
"image": null
}
],
"componentGroupName": "Back Number Components",
"audio": null,
"image": null
}
]
}
]
}
If I'm correctly getting your requirement the only id which matches your criteria would be db7ae266-bf79-4d63-984a-aea1aa7af460 and it can be fetched using the following JsonPath expression:
$.data[?(#.productId == '123ecc29f29-bc03-41d7-b107-db3be8103216')].componentGroups.*.components[?(#.componentConsumerSelectionType == 2)].id
Demo (assumes JsonPath Tester mode of the View Results Tree listener):
More information: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

Issue trying to assert Response structure based on type

Laravel Version: 6.20.30
PHP Version: 7.2.8
Database Driver & Version: Mysql 5.7
Description:
The issue I'm facing is that I need to test the structure of a response in which some properties are look-alike
Steps To Reproduce:
this is the response to test against :
[
{
"id": 1,
"product_id": 1,
"section_id": 1,
"image_id": null,
"html_id": 1,
"index": 0,
"name": "zip_2MB",
"description": "Error ex sed numquam et odit minima quia sunt. Praesentium in ea numquam. Alias ut pariatur voluptates modi velit veniam aspernatur accusantium. Aut facilis minus reprehenderit praesentium eum.",
"title": "Slide #53",
"backup": false,
"required": true,
"emailable": 0,
"type": 0,
"asset_id": null,
"thumb_id": null,
"image": null,
"html": {
"id": 1,
"product_id": 1,
"zip_id": 1,
"thumb_id": 1,
"name": "zip_2MB",
"rank": 0,
"created_at": "2021-08-11 13:24:42",
"updated_at": "2021-08-11 13:24:42",
"deleted_at": null,
"thumb": {
"id": 1,
"user_id": null,
"key": "archive/zip_2MB.zip",
"bucket": "symmetryk-assets-testing",
"region": "eu-west-2",
"cdnURL": "https://symmetryk-assets-testing.s3.eu-west-2.amazonaws.com/archive/zip_2MB.zip",
"size": 2036861,
"size_thumb": 0,
"size_preview": 0,
"mime_type": "application/zip",
"extension": "zip",
"width": null,
"height": null,
"duration": null,
"viewed": null,
"created_at": "2021-08-11 13:24:42",
"updated_at": "2021-08-11 13:24:42",
"deleted_at": null
},
"html": {
"id": 1,
"user_id": null,
"key": "archive/zip_2MB.zip",
"bucket": "symmetryk-assets-testing",
"region": "eu-west-2",
"cdnURL": "https://symmetryk-assets-testing.s3.eu-west-2.amazonaws.com/archive/zip_2MB.zip",
"size": 2036861,
"size_thumb": 0,
"size_preview": 0,
"mime_type": "application/zip",
"extension": "zip",
"width": null,
"height": null,
"duration": null,
"viewed": null,
"created_at": "2021-08-11 13:24:42",
"updated_at": "2021-08-11 13:24:42",
"deleted_at": null
}
}
},
{
"id": 2,
"product_id": 1,
"section_id": 1,
"image_id": 2,
"html_id": null,
"index": 1,
"name": "file_example_JPG_500kB",
"description": "Et voluptatem et corporis in.",
"title": "Slide #78",
"backup": false,
"required": false,
"emailable": 0,
"type": 2,
"asset_id": 2,
"thumb_id": 2,
"image": {
"id": 2,
"product_id": 1,
"image_id": 2,
"thumb_id": 2,
"name": "file_example_JPG_500kB",
"rank": 1,
"created_at": "2021-08-11 13:25:23",
"updated_at": "2021-08-11 13:25:23",
"deleted_at": null,
"thumb": {
"id": 2,
"user_id": null,
"key": "image/file_example_JPG_500kB.jpeg",
"bucket": "symmetryk-assets-testing",
"region": "eu-west-2",
"cdnURL": "https://symmetryk-assets-testing.s3.eu-west-2.amazonaws.com/image/file_example_JPG_500kB.jpeg",
"size": 555181,
"size_thumb": 0,
"size_preview": 0,
"mime_type": "image/jpeg",
"extension": "jpeg",
"width": null,
"height": null,
"duration": null,
"viewed": null,
"created_at": "2021-08-11 13:25:23",
"updated_at": "2021-08-11 13:25:23",
"deleted_at": null
},
"image": {
"id": 2,
"user_id": null,
"key": "image/file_example_JPG_500kB.jpeg",
"bucket": "symmetryk-assets-testing",
"region": "eu-west-2",
"cdnURL": "https://symmetryk-assets-testing.s3.eu-west-2.amazonaws.com/image/file_example_JPG_500kB.jpeg",
"size": 555181,
"size_thumb": 0,
"size_preview": 0,
"mime_type": "image/jpeg",
"extension": "jpeg",
"width": null,
"height": null,
"duration": null,
"viewed": null,
"created_at": "2021-08-11 13:25:23",
"updated_at": "2021-08-11 13:25:23",
"deleted_at": null
}
},
"html": null
}
]
this is can be returned from a route for easy testing.
$request = $this->get('/dummy-url-to-return-the-response');
$request
->assertJsonStructure(
[
'*' => [
'id',
'product_id',
'section_id',
'image_id',
'html_id',
'index',
'name',
'description',
'title',
'backup',
'required',
'emailable',
'type',
'asset_id',
'thumb_id',
'image' => [
'*' => [
'id',
'product_id',
'image',
'thumb'
]
],
'html' => [
'*' => [
'id',
'product_id',
'image',
'thumb'
]
]
]
]
)
If an object have an html object, the image object is null and vis versa.
Keep in mind that the structure was truncated for easier follow so assuming that I am writing this correctly, this is the message I keep getting.
Argument #2 of PHPUnit\Framework\Assert::assertArrayHasKey() must be an array or ArrayAccess

Laravel apply sortBy to a related models collection

I am using the below code:
$greatDeals = $greatDealsinitial->sortBy(function ($deal, $key) {
return $deal->hotel->room[0]->price;
});
Here room is an array, I want to sort this collection by price in the room array.
But I can't use return $row->hotel->room->price;
So how can I sort this?
my collection :
[
{
"id": 2,
"hotel_id": 1,
"deal_code": "sfg",
"date": "2018-04-13 00:00:00",
"discount": 12,
"status": 1,
"created_at": "2018-04-13 11:21:18",
"updated_at": "2018-04-13 11:21:18",
"deleted_at": null,
"client_id": 1,
"hotel": {
"id": 1,
"name": "Aloft Dongguan Songshan Lake",
"address": "Dongguan, China, 511700",
"phone": "76982106666",
"country": "101",
"country_name": "India",
"state": "35",
"state_name": "Tamil Nadu",
"city": "3551",
"city_name": "Abiramam",
"area": null,
"pincode": "511700",
"nearest_airport": null,
"nearest_railway": null,
"star": null,
"check_in": null,
"check_out": null,
"lat": "22.929869",
"lng": "113.89232800000002",
"description": null,
"astatus": "1",
"status": "0",
"created_at": "2018-04-13 10:27:30",
"updated_at": "2018-04-13 10:27:48",
"client_id": 1,
"hotel_age": null,
"hotel_privilege": "asdf",
"departure": "sdaf",
"checkout_fee": "asdf",
"book_policy": "sadf",
"hotel_secured": null,
"hotel_pets": null,
"hotel_other": null,
"room": [
{
"id": 3,
"roomtype_id": 2,
"room_count": null,
"max_adult": 2,
"max_children": 1,
"capacity": 3,
"room_number": null,
"floor": null,
"number": null,
"name": null,
"city_name": "Abiramam",
"city": 3551,
"price": "200.00",
"extra_bed_price": null,
"astatus": "1",
"status": "0",
"created_at": "2018-04-13 12:37:11",
"updated_at": "2018-04-13 12:37:52",
"deleted_at": null,
"client_id": 1,
"hotel_id": 1
},
{
"id": 1,
"roomtype_id": 1,
"room_count": null,
"max_adult": 2,
"max_children": 1,
"capacity": 3,
"room_number": null,
"floor": null,
"number": null,
"name": null,
"city_name": "Abiramam",
"city": 3551,
"price": "435.00",
"extra_bed_price": null,
"astatus": "1",
"status": "0",
"created_at": "2018-04-13 10:33:24",
"updated_at": "2018-04-13 11:21:38",
"deleted_at": null,
"client_id": 1,
"hotel_id": 1
}
]
}
},
{
"id": 4,
"hotel_id": 2,
"deal_code": "ertgerf",
"date": "2018-04-13 00:00:00",
"discount": 1,
"status": 1,
"created_at": "2018-04-13 11:47:39",
"updated_at": "2018-04-13 11:53:45",
"deleted_at": null,
"client_id": 2,
"hotel": {
"id": 2,
"name": "Temperance Lane",
"address": "Temperance Ln, Sydney NSW 2000, Australia",
"phone": "9842814927",
"country": "14",
"country_name": "Austria",
"state": "281",
"state_name": "Carinthia",
"city": "6843",
"city_name": "Maria Rain",
"area": "test",
"pincode": "2000",
"nearest_airport": "demo",
"nearest_railway": "test",
"star": null,
"check_in": "09:30 AM",
"check_out": "04:30 PM",
"lat": "-33.86963590000001",
"lng": "151.20667979999996",
"description": "test description",
"astatus": "1",
"status": "0",
"created_at": "2018-04-13 10:43:16",
"updated_at": "2018-04-13 11:41:25",
"client_id": 2,
"hotel_age": null,
"hotel_privilege": "testtesttesttesttesttesttesttesttesttesttest",
"departure": "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest",
"checkout_fee": "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest",
"book_policy": "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest",
"hotel_secured": null,
"hotel_pets": null,
"hotel_other": "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest",
"room": [
{
"id": 2,
"roomtype_id": 1,
"room_count": null,
"max_adult": 2,
"max_children": 3,
"capacity": 5,
"room_number": null,
"floor": null,
"number": null,
"name": null,
"city_name": "Maria Rain",
"city": 6843,
"price": "345.00",
"extra_bed_price": null,
"astatus": "1",
"status": "0",
"created_at": "2018-04-13 10:46:04",
"updated_at": "2018-04-13 10:47:05",
"deleted_at": null,
"client_id": 2,
"hotel_id": 2
}
]
}
}
]
This sorts the rooms of each hotel per price:
$greatDealsinitial->each(function($deal) {
$deal->hotel->setRelation('room', $deal->hotel->room->sortBy('price'));
});
$greatDeals = $greatDealsinitial->hotel->room->sortBy('price')
if this array looks
[
['price' => 0],
['price' => 1],
['price' => 3]
]

How to filter laravel collection from given data

i have a collection data
{
"success": true,
"doctor": [
{
"id": 1,
"name": "Dr. Mayank",
"dob": "1975-01-01",
"about": "This is description",
"status": 1,
"rating": 2,
"rating_given_by": 1,
"alternative_number": "7686876876",
"profile_photo": [],
"speciality": [
{
"id": 3,
"name": "Acupuncture",
"image": null,
"dashboard_flag": 1
},
{
"id": 4,
"name": "Acupuncturist",
"image": null,
"dashboard_flag": 1
},
{
"id": 1,
"name": "Accident and emergency medicine",
"image": "http://192.168.16.21/remidify/media/174/detail.png",
"dashboard_flag": 1
}
],
"service": [
{
"id": 78,
"name": "Correction of gummy smile",
"cost": "12.00"
},
{
"id": 77,
"name": "Dental aesthetics",
"cost": "43.00"
}
],
"clinics": [
{
"id": 1,
"name": "akram",
"entity_id": 1,
"entity_type": "App\Doctor",
"contact_number": "2132132132132",
"status": 0,
"consultancy_fee": "12.00",
"available_today": "No",
"owner_name": "Dr. Mayank",
"pivot": {
"doctor_id": 1,
"clinic_id": 1
},
"address": {
"id": 1,
"address_1": "asdasdasdsa",
"address_2": "",
"locality": "downtown",
"city": "noida",
"state": "up",
"postal_code": "41561566"
},
"speciality": [],
"service": [
{
"id": 11,
"name": "Laminates",
"cost": "20.00"
},
{
"id": 12,
"name": "Dental surgery",
"cost": "300.00"
}
],
"clinic_image": [
{
"id": 7,
"model_id": 1,
"model_type": "App\Clinic",
"collection_name": "clinic_image",
"file_name": "1494863957588.566162.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/7/1494863957588.566162.jpg"
}
],
"id_image": [
{
"id": 8,
"model_id": 1,
"model_type": "App\Clinic",
"collection_name": "id_image",
"file_name": "1494863966218.348877.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/8/1494863966218.348877.jpg"
}
],
"location": {
"id": 1,
"latitude": 0,
"longitude": 0,
"entity_id": 1,
"entity_type": "App\Clinic",
"created_at": "2017-05-16 03:00:10",
"updated_at": "2017-05-16 03:00:10"
},
"clinic_timings": [
{
"day": "sun",
"opens_at": "09:28:00",
"closes_at": "21:28:00"
}
]
}
],
"education": [
{
"id": 19,
"degree": "MBBS",
"university": "Univercity",
"year": "2017",
"entity_id": 1,
"entity_type": "App\Doctor",
"created_at": "2017-05-16 05:44:11",
"updated_at": "2017-05-16 05:44:11",
"location": "Delhi"
}
],
"experience": [
{
"id": 19,
"hospital": "Hospital name",
"post": "pta ni hai",
"from": "1970-01-01",
"to": "0000-00-00",
"entity_id": 1,
"entity_type": "App\Doctor",
"created_at": "2017-05-16 05:44:12",
"updated_at": "2017-05-16 05:44:12",
"location": "Locations12",
"is_currently_working": 1
}
],
"registration": {
"id": 1,
"registration_number": "Reg # 2324324",
"registration_year": 1975,
"registration_council": "Council",
"experience": null,
"doctor_id": 1,
"created_at": "2017-05-16 02:56:37",
"updated_at": "2017-05-16 02:56:37",
"adhaar_number": "232131231232",
"id_proof": [
{
"id": 2,
"model_id": 1,
"model_type": "App\DoctorRegistration",
"collection_name": "id_proof",
"file_name": "1494863680447.329102.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/2/1494863680447.329102.jpg"
}
],
"registration_proof": [
{
"id": 3,
"model_id": 1,
"model_type": "App\DoctorRegistration",
"collection_name": "registration_proof",
"file_name": "1494863687436.266846.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/3/1494863687436.266846.jpg"
}
],
"qualification_proof": [
{
"id": 4,
"model_id": 1,
"model_type": "App\DoctorRegistration",
"collection_name": "qualification_proof",
"file_name": "1494863695576.803955.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/4/1494863695576.803955.jpg"
}
]
},
"preference": {
"availability": 1,
"appointment_confirmation_method": "manual",
"average_time": 7,
"holiday_from": null,
"holiday_till": null,
"patients_per_hour": null,
"preferred_appointment_type": "timeslot",
"appointment_frequency": null,
"preferred_payment_method": [
{
"payment_method": "cash"
},
{
"payment_method": "online"
}
]
},
"user": null,
"doctor_clinic": [
{
"doctor_id": 1,
"clinic_id": 1,
"consultancy_fee": "12.00",
"deleted_at": null,
"workdays": [
{
"day": "sun",
"available": 1,
"workhours": [
{
"from": "09:28:00",
"to": "21:28:00"
}
]
}
],
"service": []
}
]
}
]
}
Now how can i find the doctors whose "about or specialty name" matches with some given search string.
Thanks in advance.
Try using dd() helper and use like this below
$youcollectionvariables = { "success": true, "doctor": [ { "id": 1, "name": "Dr. Mayank", "dob": "1975-01-01"................. }
dd($youcollectionvariables)
you will see a formatted data and can find what you need clearly.
Hope that helps.

Resources