2
votes

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?

2
what exactly do you want to extract? what does " the first free slot". Can you give sample output?ant

2 Answers

1
votes

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:

0
votes

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.