2

I am trying to create a JMeter script for an online insurance application that creates repair bookings for automotive claims. One of the responses to this application returns a JSON object that has the time slots available and unavailable to book repair jobs. An example of the JSON is below.

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

This shows the hours 7am, 8am, 9am and 10am. With timeslots 7:45, 7:30, 7:00 etc. A 1 against the minute slot indicates that this slot is free. So the first free slot is 7:45.

How can I use a regular expression to extract the first free slot?

I came up with this regex to get the hour slot... "(\d{1})":{"\d{2}":1, but can't work out how to accurately extract the minute slot.

I'm wondering whether it would be easier to do this using a BSF Postprocessor and some javascript. Unfortunately my scripting skills are poor.

Can anyone offer me any help in how to extract this info using a regex or possibly using a BSF post processor?

vcsjones
  • 138,677
  • 31
  • 291
  • 286
chucknor
  • 837
  • 2
  • 18
  • 33
  • what exactly do you want to extract? what does " the first free slot". Can you give sample output? – ant Jun 25 '12 at 12:50

2 Answers2

1

More powerful - as well as more complicated - way will be implementing JSON response processing using BeanShell scripting (~ java) + any json-processing library (json-rpc-1.0 e.g.).

Look into the links below for details/samples/code:

Community
  • 1
  • 1
Aliaksandr Belik
  • 12,725
  • 6
  • 64
  • 90
  • I want to extract the first free slot so 7:45. The sample output is in my original post but here it is again...{"7":{"45":1,"30":1},"8":{"45":1,"30":1,"15":1,"00":1},"9":{"45":1,"30":1,"15":0,"00":1},"10":{"45":1,"30":1,"15":1,"00":1}}. – chucknor Oct 08 '12 at 02:06
0

Hmm, if you're trying to find just the first two number occurrences you can use something like this:

(\w+)(?:[\D]*)(\w*)

I posted the expression on regexplanet so you can test various input JSONs.

Marko Bonaci
  • 5,622
  • 2
  • 34
  • 55