How to filter value in JSON response using expression?



Response JSON Example:
{
    "search": {
        "street": "31, Trevor Street",
        "state": "AL",
        "postal_code": "67901",
        "phone": "6574727441",
        "name": "John Corp",
        "country": "US",
        "city": "Alabama"
    },
    "results": {
        "speedylocal.com": {
            "status": "no-result"
        },
        "chamberofcommerce.com": {
            "status": "complete",
            "data": {
                "site_logo": "http://cdn.verifymybiz.com/",
                "phones": [
                    "271893712"
                ],
                "name": "Sample",
                "live_link": "https://www.chamberofcommerce.com/",
                "full_address": "Testing street",
                "country": "US",
                "accurate": false
            }
        },
        "facebook.com": {
            "status": "in-progress"
        },
     
    }
}


Dependency :

POM.XML
<dependency> 
   <groupId>com.jayway.jsonpath</groupId>  
  <artifactId>json-path</artifactId> 
   <version>2.3.0</version>  
  <exclusions>     
   <exclusion>      
      <artifactId>jcl-over-slf4j</artifactId>     
       <groupId>org.slf4j</groupId>       
 </exclusion>       
 <exclusion>      
      <artifactId>slf4j-api</artifactId>     
       <groupId>org.slf4j</groupId>    
    </exclusion> 
   </exclusions></dependency>



Sample.java

I saved the rest API response in Response object from RestAssured. 



//Reference : https://github.com/json-path/JsonPath

public  String getResponseValueUsingJayway(String objectXpath){
      return com.jayway.jsonpath.JsonPath.read
(response.jsonPath().prettify(),objectXpath).toString();}


Test.java

Example 1:

String Result=object.getResponseValueUsingJayway("$.results");


Example 2:

String Result=object.getResponseValueUsingJayway("$.results..status");




How to use graphql query in postmark and how to automate graphql using restassured api ?


How to use graphql query in postmark ?


1. Open the graphql in web browser and type Query or mutation. which you want to execute in postman.



2. Open developer console and choose the network tab. and then hit the play button in web browser to execute the graphql query


3. In network tab, Right click on the request send to the server and then  select copy->copy as cURL




4. Open postmat and click the import button at the top




5. click on Paste Raw text tab




6. Paste the copied request and then click import button


7. Once the request is import to postmar, click the send button and verify the graphql request return the response.




8. Result of my graphql request in Postmark






how to automate graphql using restassured api ?


Sample snippet of how to use graphql query in restassured api.

Once the request is imported in postmark, copy the data and send the request using restassured api as like a normal api.


response=given()
.body("{"query":"{\n  viewer {\n    login\n  }\n}\n","variables":{},"operationName":null}")
.when()
.contentType(ContentType.JSON)
.post("https://graphql-explorer.githubapp.com/graphql/proxy");

response.print();


Convert resultset object to list of map

Convert the resultset object to list of map In some cases, while we doing API automation, we need to fetch the value from the DB and hav...