如何从JMeter JSON响应中获取所需的键值

时间:2018-06-21 14:12:20

标签: json jmeter jmeter-4.0

我想验证我的JSON格式的API响应。就我而言,我想获取并验证“ SysCreatedUserId”或特定“ Id”的“ IsActive”值。请找到以下JSON文件。我尝试使用JSON断言,但到目前为止没有成功。有人可以帮忙吗?

[
  {
    "Version": null,
    "StatusCode": 200,
    "Result": [
      {
        "AccountId": "e26290ff-38c9-4733-a3d3-e57d5f8318ef",
        "OrganizationLevelTypeId": "b2761fb7-cb1e-4860-81c4-7205e7b742d7",
        "Name": "LevelName_-928016457_updated",
        "ParentId": null,
        "IsActive": true,
        "RowVersion": "",
        "IsWolfpack": false,
        "LastActivityDate": "2018-06-21T09:38:50.83",
        "WolfpackConfiguration": {
          "Id": "00000000-0000-0000-0000-000000000000",
          "LevelId": "00000000-0000-0000-0000-000000000000",
          "AssociationLevelId": null,
          "IsPublic": false,
          "Level": null,
          "AssociationLevel": null
        },
        "ChildOrganizationLevels": null,
        "OrganizationLevelUsers": [],
        "FragmentSettings": null,
        "OrganizationLevelCode": "00000000-0000-0000-0000-000000000000",
        "SysCreatedUserId": "720abe00-1267-4ede-aa0f-505e11f806de",
        "SysEditedUserId": "720abe00-1267-4ede-aa0f-505e11f806de",
        "SysCreatedDateTime": "2018-06-21T09:38:50.83",
        "SysEditedDateTime": "2018-06-21T09:38:51.82",
        "Id": "3cb5ee8d-1382-49fc-850c-013c65ab81b0"
      },
      {
        "AccountId": "e26290ff-38c9-4733-a3d3-e57d5f8318ef",
        "OrganizationLevelTypeId": "b2761fb7-cb1e-4860-81c4-7205e7b742d7",
        "Name": "LevelName_-1910968947_updated",
        "ParentId": null,
        "IsActive": false,
        "RowVersion": "",
        "IsWolfpack": false,
        "LastActivityDate": "2018-06-21T10:26:38.28",
        "WolfpackConfiguration": {
          "Id": "00000000-0000-0000-0000-000000000000",
          "LevelId": "00000000-0000-0000-0000-000000000000",
          "AssociationLevelId": null,
          "IsPublic": false,
          "Level": null,
          "AssociationLevel": null
        },
        "ChildOrganizationLevels": null,
        "OrganizationLevelUsers": [],
        "FragmentSettings": null,
        "OrganizationLevelCode": "00000000-0000-0000-0000-000000000000",
        "SysCreatedUserId": "720abe00-1267-4ede-aa0f-505e11f806de",
        "SysEditedUserId": "720abe00-1267-4ede-aa0f-505e11f806de",
        "SysCreatedDateTime": "2018-06-21T10:26:38.28",
        "SysEditedDateTime": "2018-06-21T10:26:39.74",
        "Id": "30ebcf1c-35a2-4135-91d0-0b2b08564361"
      }
    ]
  }
]

1 个答案:

答案 0 :(得分:0)

您需要使用Filter Expression,例如:

$..[?(@.Id == '3cb5ee8d-1382-49fc-850c-013c65ab81b0')].SysCreatedUserId

演示:

JMeter JSON PAth Extractor

更多信息:JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios