-2

I am using REST-API for testing I am stuck where I am checking the response with some specific string. please refer below info I got the response from a request is

{  
 "clusters":[  
  {  
     "id":10,
     "name":"HP2",
     "status":2,
     "statusDisplay":"HParihar@4info.com",
     "lastModifiedBy":"HParihar@4info.com",
     "lastModifiedTime":"06/08/2017 23:42",
     "sitesAppsCount":0
  },
  {  
     "id":799,
     "name":"Regression_cluster_111_09",
     "status":2,
     "statusDisplay":"admin@4info.net",
     "lastModifiedBy":"admin@4info.net",
     "lastModifiedTime":"07/11/2017 08:19",
     "sitesAppsCount":0
  }
]} 

and I wanted to match just

     "name":"Regression_cluster_111_09",
     "status":2,
     "statusDisplay":"admin@4info.net",
     "sitesAppsCount":0

right side values I'll be keeping as hard coded. any guesses?

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
indrajit narvekar
  • 143
  • 1
  • 6
  • 18

2 Answers2

4

Since you are only checking those 4 parameters are in response or not.

Do no use regex for this.

Use jsonObject's find key/value feature.

Check whether the values to the keys are there.

If key/value is null, the parameter is not in response.

Jisu Hong
  • 724
  • 1
  • 7
  • 22
0

I got my answer I used the following regex

"name":"Regression_cluster_111_09","status":2,"statusDisplay":"admin@4info.net","lastModifiedBy":"[a-z]+@[0-9a-z]+\.[a-z]+","lastModifiedTime":"[0-9]{2}\/[0-9]{2}\/[0-9]{4}\ [0-9]{2}:[0-9]{2}","sitesAppsCount":0

or I can simply use

"name":"Regression_cluster_111_09","status":2,"statusDisplay":"admin@4info.net",.+"sitesAppsCount":0

thank you all

indrajit narvekar
  • 143
  • 1
  • 6
  • 18