0

I have following values

[ { "id": ID1, "XXX": "XXXX", "XXX": "XXX XXX", "xxx": { "XXXX": "XXXX", "XXXXX": "XXXX" }, "XXXX": "[email protected]", "XXXXX": "XXXX", "XXXX": XXX, "Section1": [ { "id": ID_Section1, "xXXX": "XXXX", "teams": { "XXXX: XXX, "XXX": "XXX XXX XXX" }, "Section2": { "id": ID_Section2, "XXXX": "XXX XX", "XXX": "XXX", "XXX": "XX-XX" }, "XXX": XXX } { "id": ID2, "XXX": "XXXX", "XXX": "XXX XXX", "xxx": { 

I need to get the value like ID1, ID2 etc. but while using the below regular expression, I am getting all the values of other ID as well like ID_Section1, ID_Section2 which I don't need.

Expression:

 "id":(.?), 

Template : $1$

I also tried to extract the value using JSON path extractor with the below command but still it is fetching all the values.

 $..id 

Any help is appreciated?

1
  • Use a json parser to parse json? Commented May 10, 2017 at 11:16

3 Answers 3

3

Simply don't use regular expressions to parse JSON.

JMeter comes with JSON Extractor which allows executing JsonPath language queries for getting data from JSON entities so you can get the "ID" you are interested in using simple query like: $[0].id

Demo:

JMeter JSON Demo

References:

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Since I needed to get all the id values, I used your solution with bit of modification. Instead of using $[0].id, I used $[*].id which did the trick for me. Thanks for the help. I have accepted your answer. Cheers
0

What about this: (?:"|')id(?:"|')\s*:\s*(?<id>ID\d+)

It captures ID1, ID2 etc. in the named capturing group id.

You can try this solution online at: https://regex101.com/

1 Comment

Thanks for the help but I was getting an error "org.apache.oro.text.MalformedCachePatternException: Invalid expression: (?:"|')id(?:"|')\s*:\s*(?<id>ID\d+) Sequence (?<...) not recognized". Anyway, I have accepted the answer provided above. Thanks for the help anyway. Cheers.
0

You can use this for the regular expression:

{\n"id":(.*?), 

It will get ID1, ID2....and store them in different variables.

2 Comments

Thanks but with the above code, I was getting 0 matching counts. Anyway, I have accepted the answer provided above. Thanks for the help anyway. Cheers.
It is working for me, you can check here regex101.com/r/5wcotU/1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.