1

what is the best approach to capture from the following array?

  • i only need to capture the value of ANY 'beginDate', e.g: 2017-05-01T08:30:00 could be a valid one in below example
  • i need to make sure the 'beschikbaar' = TRUE for the date that i'm capturing

i tried using json path extractor with similar lines: $..[?(@.beschikbaar == 'true')].beginDate but i'm facing syntax errors that i cant fix due to my limited regex/json path knowledge

the example array is;

{

"data":
[
    [
        {
            "beginDate":"2017-05-01T08:00:00",
            "eindDate":null,
            "beschikbaar":false
        },
        {
            "beginDate":"2017-05-01T08:15:00",
            "eindDate":null,
            "beschikbaar":false
        },
        {
            "beginDate":"2017-05-01T08:30:00",
            "eindDate":"2017-05-01T10:30:00+02:00",
            "beschikbaar":true
        },
        {
            "beginDate":"2017-05-01T08:45:00",
            "eindDate":"2017-05-01T10:45:00+02:00",
            "beschikbaar":true
        },
        {
            "beginDate":"2017-05-01T09:00:00",
            "eindDate":"2017-05-01T11:00:00+02:00",
            "beschikbaar":true
        },
        {
            "beginDate":"2017-05-01T09:15:00",
            "eindDate":"2017-05-01T11:15:00+02:00",
            "beschikbaar":true
        },
        {
            "beginDate":"2017-05-01T09:30:00",
            "eindDate":"2017-05-01T11:30:00+02:00",
            "beschikbaar":true
        },
        {
            "beginDate":"2017-05-01T09:45:00",
            "eindDate":"2017-05-01T11:45:00+02:00",
            "beschikbaar":true
        },
        {
            "beginDate":"2017-05-01T10:00:00",
            "eindDate":"2017-05-01T12:00:00+02:00",
            "beschikbaar":true
        },
0

2 Answers 2

2

Don't use regular expressions for JSON data, JMeter provides JSON Extractor designed to work with JSON data via JSON Path Language so you should be able to get your "beginDate" with the query like:

$..[?(@.beschikbaar == true)].beginDate

Demo:

JMeter Conditional JSON

Check out JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios article for more detailed explanation and few more examples.

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

1 Comment

oh crap... i used 'true' instead of just plain true and wondered why it didnt work for an hour :) thanks sir
1

You can try this

(?s)\{.*?\"beginDate\":\"([^{]*?)\"[^{]+\"beschikbaar\":true.*?\}

(?s) is single-line modifier which makes . match the line break

You can test it at http://www.regexplanet.com/advanced/java/index.html

And set Template to $1$ means using the first group

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.