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

    Join Date
    Jun 2012
    Posts
    7
    Rep Power
    0

    Parsing JSON response in JMeter


    Hi all,

    Hopefully, I am posting this in the correct forum.

    I am using JMeter to create a test for a web application that handles insurance claims i.e creates repair bookings for motor claims. One of the requests returns a list of available time slots that can be used for the booking as a JSON object like so ...

    {"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}}

    This example response shows that there are no free slots for hour 7, as there is a 0 against each of its slots 7:45, 7:30 and 7:15 however there is a free slot at 8:15 indicated by the 1. I need to be able to extract this time slot and store in variable to be used for the next request.

    I tried to use a regular expression but this proved to difficult (for me anyway ). I was wondering if I could use a bean shell post processor to process the JSON response and extract a free time slot and then store this in a variable.

    Any help would be greatly appreciated.

    regards,

    Tam.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0
    I don't know the answer to your exact question, but I know that as far as using JSON now I am just using this JSONData.com site, cuz like you said it is hard to translate. The site is in beta right now, but free and getting updates every day. Hope this helps in the future
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0
    It looks like that you'll need JSONPathExtractor which is available through plugin.

    Parsing JSON with regular expressions is not very good idea as it's nature is multiline and creating a relevant regex might appear to be a headache.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    67
    Rep Power
    0
    Why can't you just parse the JSON object as an object and access the properties directly?

    Comments on this post

    • web_loone08 agrees
    http://kawaii-nation.com (^._.^)ノ
  8. #5
  9. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,188
    Rep Power
    184
    The easiest way would be to use the jQuery $.getJSON() API. Then you could store (using the new Global push() API) the variable in an object. That way; you could access multiple different selected time slots.

IMN logo majestic logo threadwatch logo seochat tools logo