使用 json 提取器将二合一关联起来

问题描述 投票:0回答:1

我是性能测试新手,目前正在研究一种需要关联 id、字段类型和 allowed_types 的场景

对于 allowed_types,我们需要选择有效负载的第一个值,例如,从下面提到的 json 中,它将是用户形成的第一个有效负载和第二个有效负载的配置文件

[
    {
        "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
    }
]

这三个变量都是相互关联的,如何用一个表达式提取所有三个变量,请帮助我

jmeter performance-testing
1个回答
0
投票

要关联提供的 JSON 中的 id、field_type 和 allowed_types,您可以结合使用过滤、映射和迭代 JSON 数据等技术。

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


console.log(extractedData);
© www.soinside.com 2019 - 2024. All rights reserved.