1

I have JSON response from which i want to extract the "transaction id" value i.e (3159184) in this case and use it in my next sampler. Can somebody give me regular expression to extract the value for the same. I have looked for some solutions but it doesn't seem to work

{
    "lock_release_date": "2021-04-03T16:16:59.7800000+00:00",
    "party_id": "13623162",
    "reservation_id": "reserve-1-81b70981-f766-4ca7-a423-1f66ecaa7f2b",
    "reservation_line_items": [
        {
            "extended_properties": null,
            "inventory_pool": "available",
            "lead_type": "Flex",
            "line_item_id": "1",
            "market_id": 491759,
            "market_key": "143278|CA|COBROKE|CITY|FULL",
            "market_name": "143278",
            "market_state_id": "CA",
            "product_name": "Local Expert",
            "product_size": "SOV30",
            "product_type": "Postal Code",
            "reserved_quantity": 0,
            "transaction_id": 3159174
        }
    ],
    "reserved_by": "user1@abc.com"
}

Here's what i'm trying in Jmeter

setting

Masud Jahan
  • 3,418
  • 2
  • 22
  • 35
Nilamber Singh
  • 804
  • 1
  • 14
  • 33
  • See [Jmeter extracting fields/parsing JSON response](https://stackoverflow.com/questions/18562060/jmeter-extracting-fields-parsing-json-response) – Wiktor Stribiżew Feb 13 '19 at 10:28

3 Answers3

3

Use JSON Extractor for JSON response rather using Regular Expression extractor.

Use JSON Path Expressions as $..transaction_id

enter image description here

Results:

enter image description here

Masud Jahan
  • 3,418
  • 2
  • 22
  • 35
2

If you really want the regular expression it would be something like:

"transaction_id"\s?:\s?(\d+)

Demo:

enter image description here

where:

  • \s? stands for an optional whitespace - this is why your expression doesn't work
  • \d+ stands for a number

See Regular Expressions chapter of JMeter User Manual for more details.


Be aware that parsing JSON using regular expressions is not the best idea, consider using JSON Extractor instead. It allows fetching "interesting" values from JSON using simple JsonPath queries which are easier to create/read and they are more robust and reliable. The relevant JSON Path query would be:

$.reservation_line_items[0].transaction_id

enter image description here

More information: API Testing With JMeter and the JSON Extractor

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
0

Simplest Regular Expression for extracting above is:

transaction_id": (.+)

Where:

  • () is used for creating capture group.
  • . (dot) matches any character except line breaks.
  • + (plus) matches 1 or more of the preceding token.

(.+?) could be used to stop looking after first instance is found.

i.e. ? makes the preceding quantifier lazy, causing it to match as few characters as possible. By default, quantifiers are greedy, and will match as many characters as possible.