I have the following Response Body JSON:
{
\"address\": [
{
\"id\": \"1234\"
}
],
\"id\": \"d1a4f010-48d9-434b-9b3a-2d2b12f5e38c\
I don't know jmeter but to get the value of second id this expression
"id"\s*:.+?"id"\s*:\s*"([^"]*)"
It will return what you want on the $1 variable in a some languages. I suppose in jmeter you can have something similar to this in order to get the first group.
Maybe ${MYREF_g1} according this page ?
try with below expression
"id": "([0-9a-z-])*+"
Using JMeter, you can use Regular Expression Extractor ...
Reference Name: myid
Regular Expression: "id": "(.+?)"
Template: $1$
Match No.: 2
If you specify using a Match No:
...
0 = Random Match
1 = First Match
2 = Second Match
etc....
Or use corresponding variable to access the match. ${myid_2}
The variables are set as follows:
myid_matchNr - Number of matches found, possibly 0
myid_n - (n = 1, 2, etc..) Generated by the template
myid_n_gm - (m = 0, 1, 2) Groups for the match (n)
myid - By itself it is always set to the default value
myid_gn - Not set at all
Or judging by this case, if you prefer just regex and your strings are exactly as stated. You could do..
],\s+"id": "(.+?)"
I tried with this:
"id":\s*"([0-9a-f\-]*)"
The given response values
{
"address": [
{
"id": "1234"
}
],
"id": "d1a4f010-48d9-434b-9b3a-2d2b12f5e38c"
}
Regular Expression to extract the second id values
Regular Expression formats
],\s\s\s\s\s"id": "(.+)"
Note
The above regex extract the following id values
d1a4f010-48d9-434b-9b3a-2d2b12f5e38c
You can use a lazy regex to find the guid directly instead of finding "id"
Something like this: ([0-9a-z-]{36}).*?
If you are not sure how to create the regex, just use an online regex maker.