Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jmeter - Json path - how to get "id" only from the part with "requests" and given "title":"subject_2" parameter?

I have a response:

{"myRequests":[],

"requests":[

{"id":"4919fe948-f4bb-4863","profileId":1,"comments":"","title":"subject_1" ...(bla-bla-bla)...,"name":"Perf_1"},

{"id":"7295814a1-d1e7-440d","profileId":1,"comments":"","title":"subject_2" ...(bla-bla-bla)...,"name":"Perf_1"},

{"id":"0b548e6c2-ec40-4875","profileId":1,"comments":"","title":"subject_1" ...(bla-bla-bla)...,"name":"Perf_1"},

{"id":"39c603faf-e3f7-4666","profileId":1,"comments":"","title":"subject_2" ...(bla-bla-bla)...,"name":"Perf_1"},

"approvedRequests":[

{"id":"83b8f6a65-da90-4b98","comments":"accept_1", ...(bla-bla-bla)...,"name":"Perf_1"},

{"id":"4db544fd1-60fe-4b72","comments":"accept_1", ...(bla-bla-bla)...,"name":"Perf_1"},

{"id":"24705ef9f-7c5c-4d43","comments":"accept_1", ...(bla-bla-bla)...,"name":"Perf_1"},

{"id":"9d5238283-3da9-4d7d","comments":"accept_1", ...(bla-bla-bla)...,"name":"Perf_1"}, ]}


I try to use

$.requests[?(@.comments=="")].id[0]

$.requests[?(@.comments=="" && @.title=="subject_2")].id[0]

but don't see effect - what I'm missing?

What should be correct json path in this case, to have "id" only from the part with "requests" and given "title":"subject_2" parameter?

question from:https://stackoverflow.com/questions/65946765/json-path-how-to-get-id-only-from-the-part-with-requests-and-given-title

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think it would be easier to go for JSON JMESPath Extractor and slightly amend your query to use pipe operator like:

requests[? comments==''].id | [0]

Demo:

enter image description here

More information: The JMeter JSON JMESPath Extractor and Assertion: A Guide


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...