0

I have to compare two json response as successful response in JMETER.

For example either I will get a response with values,

[
    {
        "id": 423082,
         "createdBy": 10000,
         "createdOn": "03/11/2016 12:04 PM"
    },
    {
         "id": 423083,
         "createdBy": 10001,
         "createdOn": "06/11/2016 12:04 PM"
    }
]

OR I will get an empty json []

Both are successful results for me.

How can I compare these results in Response Assertion or JSON Path Extractor as successful results.

Paweł Mikołajczuk
  • 3,692
  • 25
  • 32
User3091
  • 221
  • 1
  • 5
  • 19
  • improve formatting – Paweł Mikołajczuk Apr 04 '16 at 12:02
  • how precise you want to be in the case the data is returned? Because simplest solution would be something like `\[(\{.*\})*\]` - checks whether it's a JSON array with 0 or more objects inside. But it can be as fancy as checking whether date is valid and so on... – timbre timbre Apr 05 '16 at 02:46

1 Answers1

0

enter image description hereCreate one regular expression extractor with regex \[(.*?)\]and give some variable name like checkpoint now apply a response assertion and pass ${checkpoint_g0}, so that if your response does not have any value than also it'll check for [] empty json otherwise it'll compare whole response

Kaushlendra Jha
  • 396
  • 1
  • 13
  • Hey its not working. I created one regular expression extractor with reference name = checkpoint and Regular Expression = \[(.*?)\] and then in my response assertion selected 'contains' and pattern to test ${checkpoint_g0}. But still its not matching when I am getting empty json []. And I have to even compare 'createdBy' so that even when json is not empty its still valid – User3091 Apr 04 '16 at 12:19
  • regular exp should be \[(.*?)\], provided response should not have any new line, else share your exact response over here – Kaushlendra Jha Apr 04 '16 at 12:48
  • My response is [] There is no space or new line. – User3091 Apr 04 '16 at 12:51
  • Sorry but its not working :( Are the other things right ? response assertion and all. I am new to JMETER – User3091 Apr 04 '16 at 12:53
  • Does the order matters ? – User3091 Apr 04 '16 at 12:54
  • yea order matters, first apply regular exp extractor then response assertion as a child of request for which you want to validate. also place one debug sampler to check is your correlation working – Kaushlendra Jha Apr 04 '16 at 12:57
  • I have tried both of them. Still its not working. I guess something else is going wrong – User3091 Apr 04 '16 at 12:57
  • Not working. In response assertion where are we suppose to pass ${checkpoint_g0} ? – User3091 Apr 04 '16 at 13:02
  • check attached image – Kaushlendra Jha Apr 04 '16 at 13:21