0

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
            }
        ]
    }
]

}

2 Answers 2

0

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:

  1. you have "=" instead of "==", see your "@.componentGroups..poolId = .pools.*.id"
  2. careful with your path; you are, at one point, in componentGroups but expecting to be in pools
Sign up to request clarification or add additional context in comments.

1 Comment

--Make your JSON path in two steps, perhaps. Two variables. Building-blocks. What do you mean by that? Can you please share an example? Sorry if it sounds confusing (I know it is confusing :) basically I need IDs of "pools" from the section where componentGroups..poolId = .pools.*.id I hope this makes a bit more sense now Please check this value: cb720883-04f1-4be4-a416-2f0c75230768 it appears twice
0

I think you need to go for 2 JSON Extractors:

  1. Get all pool ids for the project you want:

    $.data[?(@.productId=='1231a29f0c3-9180-4cd7-a5c7-282f6689c31a')].pools.*.id
    

    enter image description here

    it will give you a random pool id as ${pool_id} JMeter Variable

    enter image description here

  2. Then you will be able to get the ids like:

    $.data.*.pools.*[?(@.id == '${pool_id}')].options.*.id
    

    enter image description here

    and this way you will get all pool ids:

    enter image description here

You can see all the JMeter Variables with all their respective values using Debug Sampler and View Results Tree listener combination.

1 Comment

Thank you so much for the creative idea! It is good but not exactly what I meant - sorry for the confusion, guys! I will share the screens below... Dima - ti ochen KRUT!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.