[Jmeter] Json Path Syntax

If you’re here, it’s probably because you need to extract variables from a Json response using JMeter. Good news! You’re on the definitive guide to master JMeter Json Extractor. Complementary to our Rest API Testing Guide, you’ll learn everything you need to master Json Path Expressions. Let’s go! And don’t panic, there is nothing difficult

If you’re here, it’s probably because you need to extract variables from a Json response using JMeter.

Good news! You’re on the definitive guide to master JMeter Json Extractor. Complementary to our Rest API Testing Guide, you’ll learn everything you need to master Json Path Expressions.

Let’s go! And don’t panic, there is nothing difficult down there. 😎

Json format

To get a better understanding of what Json is, here is an example Json document:

Json path syntax

1 JSON Path Description
2 $ The root object/element, all JSON Path usually start with this sign.
3 . Child operator, use this dot to move from parent to child.
4 [] Using these braces, include with the index to access the elements of an array. Note: index of array start from 0
5 * Wildcard. All objects/elements regardless their names.
6 .. Recursive descent
7 @ Indicate the current object, element
8 ?() Apply a filter (script) expression

Now, I will show with you guys some examples:
1.
Following the above Json example, I want to get name is “Zack” and age is 30 :
So, my Json path: $.name and $.age

I want to get Value of hobbies. So:

  • $.hobbies[0] will return value “music”
  • $.hobbies[1] will return value “football”
  • $.hobbies[2] will return value “movies”

I have another example like that:

JSON Path Description
$.store.* All things, both books and bicycles
JSON Path Description
$.store..price The price of everything
JSON Path Description
$..book[-2:] The second to last book
JSON Path Description
$..book[0,1] The first two books
JSON Path Description
$..book[:2] All books from index 0 (inclusive) until index 2 (exclusive)
JSON Path Description
$..book[1:2] All books from index 1 (inclusive) until index 2 (exclusive)
JSON Path Description
$..book[2:] Book number two from tail
JSON Path Description
$..book[?(@.isbn)] All books with an ISBN number
JSON Path Description
$..book[?(@.price<10)] All books in store cheaper than 10
JSON Path Description
$..book[?(@.price <= $[‘expensive’])] All books in store that are not ”expensive”
JSON Path Description
$..book[?(@.author =~ /.*REES/i)] All books matching regex (ignore case)
JSON Path Description
$..* Give me every thing
JSON Path Description
$..book.length() $..book.length()

Nguồn: viblo.asia

Bài viết liên quan

9 Mẹo lập trình Web “ẩn mình” giúp tiết kiệm hàng giờ đồng hồ

Hầu hết các lập trình viên (kể cả những người giỏi) đều tốn thời gian x

Can GPT-4o Generate Images? All You Need to Know about GPT-4o-image

OpenAI‘s GPT-4o, introduced on March 25, 2025, has revolutionized the way we create visual con

Khi nào nên dùng main, section, article, header, footer, và aside trong HTML5

HTML5 đã giới thiệu các thẻ ngữ nghĩa giúp cấu trúc nội dung web một cách có

So sánh Webhook và API: Khi nào nên sử dụng?

Trong lĩnh vực công nghệ thông tin và phát triển phần mềm, Webhook và API là hai th