How to read Array of Nested JSON Response in Postman ?
Last Updated :
27 Mar, 2024
We know that the postman is the one who delivers the letters sent by your friends, colleagues, or relatives and acts as a bridge of communication. Here Postman refers to the development of API that acts as a bridge or communication between different programs.
In other words, it is an API client, made for developing, testing, and management. You can download Postman on Windows, Linux, and Mac.
JSON stands for JavaScript Object Notation where data is in the form of key-value pairs. It is an alternative way to send or transmit data between servers and web applications. It starts and ends with curly brackets {}.
Sample JSON Data:
We have here an object that contains the property's name, age, city, hobbies, etc. The key is name and the value here in this example is Jhonson.
{
"name": "Johnson",
"age": 42,
"city": "New Castle",
"hobbies": ["boxing", "traveling", "reading"],
"Roll No ": 123,
}
Nested JSON Example:
Nested JSON object is defined as the JSON Object included in another object like in this example. We have included object address which have its own object street, city and zip code. Complex JSON includes combination of objects and arrays.
{
"name": "Johnson",
"age": 42,
"address": {
"street": "123 Street",
"city": "New Castle",
"zipcode": "NC1210003"
},
"Roll No": 123,
}
How Postman works?
- As you know we in the Postman send request to the server and get in return response from the server back.
- Open the desktop app and using + sign create a new workspace. Enter the url required and use get to fetch the data.
- It is not required to use https://. Postman Get method itself add it.
- GET method is to get the data from the url.
- POST method is to create the new data.
- PUT method is to update the data.
- PATCH method is to partially update the data.
- DELETE method is to delete the data.
- If we search HTTPS method, we will get various API method.
- For every request there is a response whether it has any contents or not present.
Let's go to the website https://reqres.in/.
url- Now copy the request /api/users/2 and type on the website https://reqres.in/api/users/2
users2- Now go to the postman and type on Get method the complete url https://reqres.in/api/users/2.
postman- You can add all these get data into your own collection and name it as per your wish. When you click on the plus (+) sign, it creates new collection. Let's name it as collection 1. We can add request and transfer the request created earlier, here we created Get Data1.
Get Data1- We can create new folder and name it as GET.
GET- Now you can just from the three dots select run collection and it will run.
Run- We can add variables by clicking on edit on collection 1 and adding the key, value.
variables- Now got to the Get data 1 and instead of website https://reqres.in/ type {{url}}.
Variables- We can then run send to check.
Variable- We can add in the test to get the response.
console.log("Hello World....");
let m = pm.variables.get("url");
console.log("the url for variable is:"+m);
- Now open the Postman console by Ctrl+Alt+C. Save and then run the test.
Postman ConsoleReading JSON
We will write some test to check the status and get response as JavaScript object.
pm.test("Status code is 200", function(){
pm.response.to.have.status(200);
});
pm.test("Validation of JSON", function(){
const res= pm.response.json();
console.log(res);
});
- Now when we save and run it, we get all the JavaScript object.
JSON Object- As you can see that we have data and it has id equal to 2. To validate we will write in test and run it.
pm.test("Status code is 200", function(){
pm.response.to.have.status(200);
});
pm.test("Validation of JSON", function(){
const res= pm.response.json();
pm.except(res.data[0].id).to.eql(2);
});
validation of id- If I write 7 instead of 2, my test gets failed.
Failed validation
Similar Reads
How to read a JSON response from a link in Python?
There is a huge amount of data available on the web and most of them are in form of (JavaScript Object Notation) JSON. But it is difficult for humans to directly read and use it. To resolve this problem in python we have different libraries which help us to read the JSON data fetched from the web. T
2 min read
How to Receive and Analyze Response in Postman ?
If you're involved in API development or testing, you know how crucial it is to receive and analyze responses accurately. Postman, a popular API development tool, provides robust features for handling responses efficiently. In this article, we'll explore how to receive and analyze responses effectiv
7 min read
How to create and send POST requests in Postman?
Postman is an API(application programming interface) development tool which helps to build, test and modify APIs. It can make various types of HTTP requests(GET, POST, PUT, PATCH), saving environments for later use, and convert save the API to code for various languages(like JavaScript, and Python).
2 min read
How to create a new request in Postman?
Postman is a development tool that is used for testing web APIs i.e. Application Programming Interfaces. It allows you to test the functionality of any application's APIs. Almost every developer uses Postman for testing purposes. We can create any type of HTTP request in it such as GET, POST, PUT, D
2 min read
How to Import cURL Request into Postman ?
Postman is an API development tool that helps us do everything related to APIs, make API calls, perform API testing, create automations, etc. This is a one-step tool to perform operations on the backend server, and show the outputs in various readable formats. In this article, we will learn how to i
2 min read
Add Nested JSON Object in Postman
Postman is a helpful tool for testing APIs and working with JSON. It lets you add nested objects to existing JSON. JSON is a simple data format for both humans and machines. Postman also lets developers send requests and view responses, which is really useful for working with JSON data. These are th
2 min read
How to set header request in Postman?
Postman is a powerful API development tool that offers a feature known as environment variables. These variables are used for efficient testing and development of APIs by allowing users to manage dynamic values across requests easily. In this article, we will learn How you can set header requests in
2 min read
How to target Nested Objects from a JSON data file in React ?
Accessing nested JSON objects is similar to accessing nested arrays. Suppose we have a JSON object called person with a nested object 'address' , and we want to access the 'city' property from the address object. We can do this using dot notation like person.address.city. This notation allows us to
3 min read
How to pass parameters in Postman requests?
Postman is an API(application programming interface) development tool that helps to build, test and modify APIs. It can make various types of HTTP requests(GET, POST, PUT, PATCH), save environments for later use, and convert the API to code for various languages(like JavaScript, and Python). In this
2 min read
How to add nested object to existing JSON using Postman ?
Postman has become a critical tool for developers around the world, particularly when dealing with JSON data. This article will guide you through the process of adding nested objects to an existing JSON using Postman, with a focus on the approaches and syntax involved. Table of Content Understanding
4 min read