correlate multiple values using json extractor

29 views Asked by At

i am new to performance testing, currently working on one scenario where we need to correlate id, field type & allowed_otypes

for allowed_types we need to pick the first value of the payload, for example from the below mentioned json it would be user form the first payload & profile from the second payload

[
    {
        "id": 12,
        "field_type": "DISPLAY_SET",
        "tooltip_text": null,
        "name_plural": "Approvers",
        "name_singular": "Approver",
        "backref_name": null,
        "backref_tooltip_text": null,
        "allow_multiple": true,
        "allowed_otypes": [
            "user",
            "groupprofile",
            "groupprofile"
        ],
        "options": null,
        "builtin_name": "approver",
        "can_view": null,
        "can_edit": null,
        "flavor": "DEFAULT",
        "tag_ds_id": null,
        "tag_schema_name": null
    },
    {
        "id": 10022,
        "field_type": "DATA_SET",
        "tooltip_text": "Approvers",
        "name_plural": "Approvers",
        "name_singular": "Approvers",
        "backref_name": "Approvers",
        "backref_tooltip_text": "Approvers",
        "allow_multiple": true,
        "allowed_otypes": [
            "profile",
            "groupprofile",
            "groupprofile"
        ],
        "options": null,
        "builtin_name": null,
        "can_view": null,
        "can_edit": null,
        "flavor": "DEFAULT",
        "tag_ds_id": null,
        "tag_schema_name": null
    }
]

all of the these three variables are interlinked to each other, how to extract all three variables with one expression, please help me

2

There are 2 answers

0
Mburu Njoroge On

To correlate the id, field_type, and allowed_types from the provided JSON, you can use a combination of techniques such as filtering, mapping, and iterating over the JSON data.

 const extractedData = jsonData.map(item => ({
    id: item.id,
    field_type: item.field_type,
    allowed_types: item.allowed_otypes
}));


console.log(extractedData);
2
Ivan G On

If you want to get 1st item from allowed_otypes JSON Array for all "payloads" you can do it using the following JSONPath expression:

$..allowed_otypes[0]

Demo:

enter image description here

More information: How to Use the JSON Extractor For Testing