Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...