You are on page 1of 9
sarsor2020 ISON Path PostProcessorin JMeter ~ JMeter VN JMeter VN Discuss & Sharing about JMeter ADVANCE, GENERAL, PRE/POST-PROCESSOR JSON Path PostProcessor in JMeter JSON Date: September 17,2016 Author: harano1109_° 5 Comments JSON is now a first class citizen in JMeter with the introduction of a new JSON Path post processor. This is available as an official component from JMeter 3.0 The JSON PostProcessor enables you to extract data from JSON responses using JSON-PATH syntax. This post processor is very similar to Regular Expression Extractor. It must be placed as a child of HTTP Sampler or any other sampler that has responses. It will allow you to extract in a very easy way text content, see JSON Path syntax. In this article, I will show you what can we do with JSON Path PostProcessor. hitpsimetervn com/2016/08/17)son-path-postprocessor-injmter! 19 ‘amor2020 {ISON Path PostProcessorin JMeter — JMeter VN Firstly, let see what’re the parameters and what do they mean in this component: Name Desciaivenasne fortis element that shown in the tee. No Veriabie Names Semi-colon soparaod namce cf variables that wilcorsintho Yoo FReule of JSON-PATH exorectiore (mut matbh number of ISON-PATH expressene! SON Pat ‘Semcolon separated JSON-PATH expressions (must mai Yes Bipressions umber of vrtables) Dofaut Vacs ‘Sem-clon soparatod dotault valuee JSON-PATH oxproseions No ‘0 not raurn ary rotalfmust maton number of vanes) Mat Numbers he SON Path query lads to mary resus, youcan choose No ‘which onels) to extract as Vatiebes + © :means random (Detaut Vaio) {+ =1 means extrac al resus hey wie named variable sane_ (where Noes fom 1 to Number of resus + X:means extras the XP sub. nis Xs creat ‘umber of matches, Fn retinas returned. Default Wilke used Compute concatenation mary resus ar found, plugh wil concat hem using No var separator and sicreit aval named ALL Source: JMeter Component Reference ‘An example of a Test Plan structure: Maem | est Plan v «> Thread Group x 2 jp@gc - Dummy Sampler > JSON Path PostProcessor 2 Debug Sampler | View Results Tree © Dummy Sampler — useful for debugging, you can put any data into “Response Data” field and make the JSON Path PostProcessor a child of the Dummy Sampler, and it will allow you to avoid sending extra requests to the server NOTE: You must follow this link to install this plugin before running my example test plan © Debug Sampler - outputs JMeter Variable values (it also can print the JMeter and System properties) © View Results Tree — visualizes the Dummy and Debug samplers output And this is JSON which will be used for all examples -ntps:ijmetermn.com/2016/09/17)sor-palh-postprocessorin-imeter! sars0r2020 ISON Path PostProcessorin JMeter — JMeter VN “title”: "Sayings of the Century", “price”: 8.95 6 7] 8] ("category”: "fiction", velyn Waugh’, 20 "author": "J. RR. Tolkien", 21 “title”: "The Lord of the Rings 22 "i "0-395-19395-8", 23 22.99 24 ) 25 26 27 28 29 30 afi view raw json-path-postprocessorjson hosted with @ by GitHub The demo file json-path-postprocessorjmx for all examples below is available here. Extract Single Value © Variable names: FIRST_AUTHOR hitpsmetervn com/2016/08/17)son-path-postprocessor-injmter! a9 sarror020 ISON Path Postrocessorin Mor ~ JMeter VN © JSON Path expressions: §.store.book{0].author You will get the FIRST_AUTHOR variable with value Nigel Rees FIRST_AUTHOR=Nigel Rees FIRST_AUTHOR_matchNr=1 Slide e+ Vlew Raut Tree Handle Multi-Match Number © Variable names: AUTHOR © JSON Path expressions: §.store.book[*].author © Match Numbers: -1 Where [*] mean all the value in book array or © Variable names: AUTHOR © JSON Path expressions: $..author © Match Numbers: -1 Where .. is recursive descent. JSONPath borrows this syntax from E4X. It will extractor and generate all variables as below: AUTHOR _1-Nigel Rees AUTHOR _4-J. R. R. Tolkien AUTHOR_matchNr=4 At this time, if you want to get the first author Nigel Rees, just use $(AUTHOR_1}. Or use the ${AUTHOR_2} to get Evelyn Waugh, etc. hitpsmetervn com/2016/08/17)son-path-postprocessor-injmter! 49 sarsor2020 ISON Path PostProcessorin JMeter ~ JMeter VN In case the Match Numbers: 0-> it will extract random a value: Nigel Rees, Evelyn Waugh, Herman Melville or J. R. R. Tolkien One more option, you can extract exactly the value which you want by using Match Numbers Example: keep the same Variable names and JSON Path expressions above Match Numbers: 1 -> AUTHOR=Nigel Rees Match Numbers: 2 -> AUTHOR=Evelyn Waugh Match Numbers: 4 -> AUTHORZJ. R. R. Tolkien, Match Numbers: 5 (greater than number of matches) -> AUTHOR (nothing) Extract with a Condition Sometimes, we need to get a value which depends on the other value, ie. get PRICE where TITLE is “The Lord of the Rings”. It’s also able to to do with JSON Path Postprocessor © Variable names: PRICE © JSON Path expressions: §..[2(@.title == “The Lord of the Rings’)].price Where U-anarray. 2() - applies a filter (script) expression. @.title == ‘The Lord of the Rings’ — the current object which has title as child with value ‘The Lord of the Rings’ Let see what will we have: or iG) +i- pikh@o ts a lS FB) pews hitpsmetervn com/2016/08/17)son-path-postprocessor-injmter! 59 ‘amor2020 {ISON Path PostProcessorin JMeter — JMeter VN For more convenience, we can also parameterize the title, it may be defined before or just extracted from the other request. The expression would be $..[2(@.title == ’$(TITLEY)} price Extract Multiple values with one PostProcessor This is the new feature for PostProcessor, no need to use multiple post processors anymore. Now, let try to extract the color and price of the bicycle at the same time. Very easy, just separate Variable Names, JSON Path, Expressions, Default Values and Match Numbers by a semi-colon ; Variable names: BIKE_COLOR;BIKE_PRICE JSON Path expressions: S..bicycle.color;S..bicycle.price Match Numbers: 1/1 Default Values: NOT_FOUND;NOT_FOUND And here are the variables we have: BIKE_COLOR=red BIKE_COLOR_matchNr=1 BIKE_PRICE=19.95 BIKE_PRICE_matchNr=1 ‘View Results Tee If you want to extract more, just add more variable as syntax above. NOTES: You should to specific all options, value and must match the number of variables. For the example above, if we just put NOT_FOUND or NOT_FOUND; for Default Values, it will cause an issue like hitpsmetervn com/2016/08/17)son-path-postprocessor-injmter! 59 ‘rarrov2020 ISON Path PostProcessorin JMeter— JMeter VN java.lang.ArrayIndexOutOfBoundsException: 1 This feature looks so awesome, right? However, in my perspective, I don’t prefer this way because it’s a little bit hard to see and manage many things between the variables. Compute concatenation var If many results are found, plugin will concat them using ‘,’ separator and store it a var named _ALL Go back the second example in this article, the only difference is the Compute concatenation var checkbox is checked. el Rees Evelyn Waugh,Herman Melville J. R. R. Tolkien genera 2 Hope this article help you can understand how to work with JSON Path in JMeter. This is my very the first post, so it may contain many errors or the content is not so good enough, T also use some content from BlazeMeter, hope you all can skip it. And if you're facing any problem while executing these samples above, or the issue just related to JSON Path in JMeter, please feel free to discuss as a comment below. Any suggestion and comment for improvement, please also leave it below. I uploaded the json-path-postprocessorjmx file with contains all examples above. It will useful for you to practice by yourself. In next article, I will do the comparison between JSON Path PostProcessor and JSON Path Extractor (plugin) to see which one is better. BASIC “ POST PROCESSOR hitpsmetervn com/2016/08/17)son-path-postprocessor-injmter! 19 sarsor2020 ISON Path PostProcessorin JMeter ~ JMeter VN Published by harano1109 View all posts by harano1109 5 thoughts on “JSON Path PostProcessor in JMeter” Add Comment 1. Pingback: ‘The shortcuts in JMeter - JMeter VN 2. Pingback: Regular Expression Extractor in JMeter - JMeter VN 3. Pingback: JSR223 with Groovy (Part 1): Variables - JMeter VN 4, Pingback: JSR223 with Groovy: Variables (Part 1) - JMeter VN 5, Pingback: List of All Posts — JMeter VN © 2020 JMETER VN BLOG AT WORDPRESS.COM. hitpsmetervn com/2016/08/17)son-path-postprocessor-injmter! a sarsor2020 ISON Path PostProcessorin JMeter ~ JMeter VN -ntps:ijmetermn.com/2016/09/17)sor-palh-postprocessorin-imeter!

You might also like