JMeter JSON Path Extractor查询问题:筛选特定条件的任务ID
JMeter JSON Path 查询方案:筛选符合条件的任务ID
需求
获取满足以下两个条件的所有任务ID:
category字段不包含Docebo(支持精确匹配或忽略大小写匹配)userTasks数组中存在completed状态为false的条目
目标JSON响应片段
{ "user": [ { "id": 3633, "guid": "j25c9340-dert0-1113f-wkk2-000008fdb94", "firstname": "abc", "lastname": "xyz", "preferredname": null, "active": true, "roleKey": 1, "userTags": [ { "id": 12345, "userKey": 2323, "tagKey": 79 }, { "id": 12332, "userKey": 1233, "tagKey": 897 }, { "id": 12313, "userKey": 1233, "tagKey": 234 }, { "id": 12345, "userKey": 4321, "tagKey": 23 }, { "id": 139334, "userKey": 3633, "tagKey": 53 } ] } ], "tasks": [ { "id": 09876, "title": "Submit Performance Report", "description": "Test data", "creatorKey": 0909, "referenceNum": null, "referenceVal": null, "dueDate": "2023-08-10T00:00:00.000Z", "goLiveDate": "2023-06-18T00:00:05.147Z", "closeDate": "2023-09-10T00:00:00.000Z", "archiveDate": null, "highPriority": false, "draft": false, "mandatory": true, "additionalDetails": "", "verificationDetails": "", "estimatedDuration": null, "estimatedDurationLabel": "30TO60MINUTES", "category": "Docebo", "level": "Individual", "journeyRole": null, "actionType": null, "verificationType": null, "externalLink": "https://testdata.b23sosaas.com/learn/course/9018/A-000M1", "isExternallyManaged": true, "sourceSystemId": 1, "externalId": "5678", "requiresProof": false, "archived": false, "lastUpdatedByStaffAt": "2023-06-17T11:47:37.062Z", "lastUpdatedByStaffKey": null, "taskOwners": [], "creator": { "id": 12312, "guid": "efrerertret-fgfg-2323-dgf33-rerer343231", "firstname": "FIRSTNAME", "lastname": "LASTNAME", "preferredname": null, "active": true, "roleKey": 6 }, "taskTags": [], "userTasks": [ { "id": "UTID123456", "dueDate": null, "lastUpdatedDate": null, "lastUpdatedAction": null, "completed": false, "requiresProof": false, "additionalDetails": null, "approverComments": null, "proofOfCompletionKey": null, "userKey": 3003, "approverKey": null, "lastUpdatedByKey": null, "taskKey": 15223, "sourceSystemId": null, "externalId": "9001", "externalUrl": null } ] }, { "id": 009911, "title": "Seminar & Seminar at Socialization Event", "description": "Learning Environment", "creatorKey": 3421, "referenceNum": null, "referenceVal": null, "dueDate": "2023-07-02T16:30:00.000Z", "goLiveDate": "2023-06-30T16:30:00.000Z", "closeDate": "2023-07-03T18:30:00.000Z", "archiveDate": null, "highPriority": false, "draft": false, "mandatory": true, "additionalDetails": "", "verificationDetails": "", "estimatedDuration": null, "estimatedDurationLabel": "90MINUTESORMORE", "category": "SEMINAR", "level": "Individual", "journeyRole": null, "actionType": null, "verificationType": null, "externalLink": "https://abc.seminar.com/learn/course/6262/I-007", "isExternallyManaged": true, "sourceSystemId": 1, "externalId": "6222 / B897JJ", "requiresProof": false, "archived": false, "lastUpdatedByStaffAt": "2023-06-17T11:47:40.466Z", "lastUpdatedByStaffKey": null, "taskOwners": [], "creator": { "id": 9800, "guid": "wew23sd2f-wejyj-2357-fg24-er3g4523fa66f", "firstname": "FIRSTSEMINAR", "lastname": "LASTSEMINAR", "preferredname": null, "active": true, "roleKey": 9 }, "taskTags": [], "userTasks": [ { "id": 4556688, "dueDate": null, "lastUpdatedDate": null, "lastUpdatedAction": null, "completed": false, "requiresProof": false, "additionalDetails": null, "approverComments": null, "proofOfCompletionKey": null, "userKey": 4546, "approverKey": null, "lastUpdatedByKey": null, "taskKey": 122445, "sourceSystemId": null, "externalId": "4566 / B7no4J", "externalUrl": null } ] } ] }
你尝试的查询语句
$.tasks.[?(@.category =~ /(?!Docebo)(.*?)/i && @.userTasks.[?(@.completed == 'false')])].id
正确的查询方案
方案1:精确匹配排除Docebo
$.tasks[?(@.category != 'Docebo' && @.userTasks[?(@.completed == false)] != empty)].id
方案2:忽略大小写排除Docebo
如果需要忽略category的大小写(比如匹配docebo、DOCebo等),使用正则匹配:
$.tasks[?(!(@.category =~ /Docebo/i) && @.userTasks[?(@.completed == false)] != empty)].id
说明
- 原查询的问题:
- 数组后多了多余的
.,正确写法是$.tasks而非$.tasks. - 嵌套的
[?()]语法错误,需要通过判断筛选后的userTasks数组非空,来确认存在符合条件的条目
- 数组后多了多余的
- 关键逻辑:
@.category != 'Docebo':精确排除category为Docebo的任务!(@.category =~ /Docebo/i):忽略大小写排除包含Docebo的category@.userTasks[?(@.completed == false)] != empty:确保userTasks中存在至少一个未完成的条目
内容的提问来源于stack exchange,提问作者Vinay Chugh
相关产品推荐
相关产品推荐

