How to Count Records in JSON array using JavaScript and Postman ? Last Updated : 19 Mar, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we are going to explore how JavaScript and Postman are used to count the number of records returned in a JSON array. Send a Request: Send a request to fetch the JSON array from your API endpoint in Postman.Access JSON Response: In the Postman test scripts tab, you can access the JSON response body using the pm.response.json() method.Count Records: Use JavaScript array methods to count the records in the JSON array. For example, you can use the length property of the array.Here I have an API endpoint of my own that returns all the users registered in my application. We are going to use this API to count the number of records returned in the JSON response. API Endpoint Steps to Count records in JSON array using JavaScript and Postman:Set Up Postman - Install and set up postman from their official website.Create Request - Open Postman and create a new request. This request can be for any API endpoint that returns a JSON response containing an array of records.Write Test Script - Go to the test tab under the endpoint input. Here type the following script to count the recordsRun the request - Send the request to the API endpoint by clicking the "Send" button.View Test Results - After running the request, switch to the "Test Results" tab in Postman. You should see the output of the test script, which will display the count of records in the JSON array.var data = pm.response.json();pm.test('Number of users returned = ' + data.length);Check the test resultsTesting the Count:If we want to check something related to the count, like checking whether it is equal to 2 or not, we can also do that with the help of a script. var data = pm.response.json();pm.test('Number of users returned = ' + data.length, function () { pm.expect(data.length).to.equal(2);});Output: Testing for only 2 records Comment More infoAdvertise with us Next Article How to Count Records in JSON array using JavaScript and Postman ? T tanyadiit7 Follow Improve Article Tags : Web Technologies Node.js Postman-API-Testing Similar Reads How to Get the Size of an Array in JavaScript To get the size (or length) of an array in JavaScript, we can use array.length property. The size of array refers to the number of elements present in that array. Syntaxconst a = [ 10, 20, 30, 40, 50 ] let s = a.length; // s => 5 The JavaScript Array Length returns an unsigned integer value that 2 min read How to use Native JavaScript Promises in Postman ? Postman is a popular tool used by developers for testing APIs. While Postman primarily offers a graphical user interface (GUI) for making HTTP requests, it also supports scripting capabilities using JavaScript. One common use case for scripting in Postman is making asynchronous requests and handling 3 min read How to Find the Length of an Array in JavaScript ? JavaScript provides us with several approaches to count the elements within an array. The length of an array lets the developer know whether an element is present in an array or not which helps to manipulate or iterate through each element of the array to perform some operation. Table of Content Usi 3 min read How to use JavaScript in Postman ? Postman is an API(application programming interface) development tool that helps to build, test and modify APIs. In this tutorial, we will see how to use JavaScript in Postman.Prerequisites:Basic HTTP conceptsKnowledge of REST APIWe will discuss the following two methods to use JavaScript in Postma 3 min read How to display response body using node.js and postman collection? This article includes step by step-by-step procedures to make a request to the API using Axios and display the response to the console as well as a visual view of the response in the Postman application. What is Postman?Postman is an API platform that is used to build and use APIs. It provides a use 3 min read Like