#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Regex to extract time slot


    Hi

    I am using JMeter to create a performance script for an insurance web app that creates repair jobs for automotive claims. The following text is what is returned from a call to get the free time slots for the repair job ..

    {"7":{"45":0,"30":0},"8":{"45":0,"30":0,"15":1,"00":1},"9":{"45":0,"30":1,"15":1,"00":1},"10":{"45": 0,"30":1,"15":1,"00":1}}

    A '1' against the minute time indicates that it is free. I need to extract the first hour that has a free time slot. In this case it will be '8' as hour 7 does not have any free slots as there is a '0' against both slots 7:45 and 7:30. For hour 8 both slots 8:15 and 8:00 are free. I know I can use the following regex to extract the minute value .."(\d{2})":1..but not sure how to extract the hour time slot.

    Any help would be very much appreciated.

    Thanks.

    Tam.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,183
    Rep Power
    9398
    That's JSON. There are ways of dealing with it that are much better than regular expressions.

    What are you using to do the AJAX?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0
    Hi requinx

    Thanks for the reply. Sorry I don't understand your question. I have used JMeter to record the test scenario and am now trying to create a test script for this. I need to make the script smart enough to find a free slot, as the slot that was selected in the recording is now no longer free.

    Thanks.

    Tam.
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,183
    Rep Power
    9398
    I'll rephrase:

    You say the text is "returned from a call"... What kind of code is doing the calling? What programming language?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0
    I'm pretty sure its Java but I'm not 100% on that. I'll find out when Im back at work tomorrow. How do you propose I extract the info from the response to JMeter if not using a regex extraction?

    Thanks.
  10. #6
  11. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,183
    Rep Power
    9398
    Originally Posted by tamnor
    How do you propose I extract the info from the response to JMeter if not using a regex extraction?
    By using something which can decode JSON. Surprisingly it doesn't seem like there's anything built-in, but json.org lists a bunch of things you can use at the bottom of their homepage.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0
    Ok. Thanks for the advice. It's definitely Java that the app is written in. I might have a look at some JMeter forums and see if I can find something.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0
    I would suggest using JSON Path Extractor available through JMeter Plugins which is the best way of dealing with JSON response structures.

    See Using the XPath Extractor in JMeter (scroll down to Parsing JSON) for detailed explanation, example queries and XPath to JSON Path mapping.

IMN logo majestic logo threadwatch logo seochat tools logo