Skip to main content

Featured

How to Visualize your JSON 🕵🏼?

A simple way to view and segregate the complex JSON Hello Peeps, Welcome back to another blog 😉. I hope everything is going well for you. Many people prefer the JSON format for APIs, databases, and other applications for a variety of reasons. Some JSON requests or responses are simple and only contain a few objects. On numerous occasions, you may be required to handle a complex response. I wrote a blog about parsing complex responses before using https://jsonpathfinder.com/ In most cases, however, you will need to further investigate your JSON payload or responses for various reasons and analytical purposes. Are you a visual learner or a fan of mind maps? Then you will undoubtedly fall in love with this tool ❤️ JSON Crack I recently came across this tool and found it’s worth sharing with the community 👓 Once you land on the home page, click “GO TO EDITOR” Now you will see a sample JSON beatified and visualized. To visualize it, clear the left side pane and paste your JSON. For instan

Useful JavaScript methods for handling arrays in API Testing using Postman!!

When I started using Postman, JavaScript was completely new to me, those Syntax, Statements etc.. I have quite some knowledge of Java, but nowhere those are related to JS:-) ha ha ha…

When you are Testing your API, most of the times you need handle JSON Arrays . Based on my experience I would say, some basic array functions would help you to write cool tests in Postman. Nothing to be scared of, it’s actually fun.

Let’s see the basic and useful functions,

Before that, let’s first define an array for using in our examples.

let names = [‘George’, ‘Annie’, ’Sofia’, ‘Paul’]

And you can directly print the names using console.log(“Person Names: “, names);

To get the property of the array,

Length: This returns the entire length of an array.

Syntax: arrayname.length

Example: console.log(names.length) // gives you the output 4

Below are some common methods used:

1.Push: This method adds the list of values to the end of the array.

Example: names.push(‘Henry’, ‘Adriana’);

console.log(names) // names = [‘George’, ‘Annie’, ’Sofia’, Paul’, ‘Henry’, ‘Adriana’]


2. Unshift: This method adds comma-separated list of values to the front of the array.

Example: names.unshift(‘Nick’, ‘Rio’);

console.log(names) // names = [‘Nick’, ‘Rio’, ‘George’, ‘Annie’, ’Sofia’, Paul’]


3. Pop: This method removes the last value of the array.

Example: names.pop();

console.log(names) // names = [‘George’, ‘Annie’, ’Sofia’]


4. Shift: This method removes the first value of the array.

Example: names.shift();

console.log(names) // names = [‘Annie’, ’Sofia’, ‘Paul’]


5. Splice: This method finds the specified position (pos) and removes n number of items from the array. Arguments are passed in here.

Example: names.splice(3, 1, ‘Ryan’);
// replaces 1 element at index 3
console.log(names);
// names = [‘George’, ‘Annie’, ’Sofia’, ‘Ryan’]


6. Slice: This method creates a copy of an array with selected elements.

Example: var newNames = names.slice(1, 3);

console.log(“New Names: “, newNames );

//newNames = [ ‘Annie’, ’Sofia’]


7. Indexof: This method returns the first element that matches the search parameter after the specified index position. Defaults to index 0.

Example: var result = names.indexOf(‘Sofia’);

console.log(“The search result index is: “, result); // The search result index is: 2

console.log(names.indexOf(‘Mark’)); // -1 (since the value is not present inside the array)


8. Join: This method returns the items in an array as a comma separated string. The separator argument can be used to change the comma to something else.

Example: var arrayString = names.join(‘-’);

console.log(“Strings present in the array: “, arrayString);

//Strings present in the array: George-Annie-Sofia-Paul

console.log(names.join()); // George, Annie, Sofia, Paul


9. Reverse: Literally, it’s the same as the name implies. This method will reverse the array for you.

Example: names.reverse();

console.log(names) //names = [‘Paul’, ‘Sofia’ ,’Annie’ ,’George’]


10. Sort: This method sorts the element of an array, and sorted array is returned.

Example: names.sort();

console.log(names) //names = [‘Annie’, ‘George’, ‘Paul’, ‘Sofia’]


Isn’t real fun?? Hope it will be helpful for writing your automated scripts for API using Postman. You can learn JS, even you are from QA background quickly! All you need is to have a passion and invest some quality time!!!


Comments

Popular Posts