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

Global functions of JavaScript!!!



Some basic knowledge about JavaScript will help you to write better scripts in Postman for your API testing automation.

We will look about some global functions and their usage. Once you learn you will know when and where to use in your script.

These global functions called globally, rather than on an object directly return their results.

1.String():

This function converts the value of an object to a string.

Eg:

var bool = Boolean(0);

result = String(bool); // false


2. encodeURI():

This function encodes the URI, represents the UTF-8 encoding of the character. It escapes all all characters except:

A-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #

The decodeURI() function to decode an encoded URI.

Eg:

const uri = ‘https://test.com/?x=шеллы';

const encoded = encodeURI(uri);

console.log(encoded); // https://test.com/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B

const decoded = decodeURI(uri);

console.log(decoded); // https://test.com/?x=шеллы


3. encodeURIComponent():

This function encodes a URI component including the special characters.

The decodeURIComponent() function to decode an encoded URI component.

Eg:

const uri = ‘#^$&%&^';

const encodedComp = encodeURIComponent(uri);

console.log(encodedComp); // %23%5E%24%26%25%26%5E

const decodedComp = decodeURIComponent(uri);

console.log(decodedComp); // #^$&%&^


4. isFinite():

This function tell if the number passed is a finite number or not and returns false if the value is +infinity, -infinity, or NaN, otherwise it returns true.

var text= isFinite(“Test”); // false

var eg = isFinite(910); // true

var eg = isFinite(null); // true, would’ve been false with the

// more robust Number.isFinite(null)


5. Number():

This method converts the variable into numbers.

Eg:

var num1 = Number(true);

console.log(num1); // 1

var num2 = Number(“123”);

console.log(num2); // 123


6. parseInt():

This function parses a string and returns an integer. Only the first number in the string is returned. If the first character cannot be converted to a number, parseInt() returns NaN.

Eg:

var int1= parseInt(“12.67”);

console.log(int1); // 12

var int2= parseInt(“45 90 12”);

console.log(int2); // 45


7.parseFloat():

This function parses a string and returns a floating point number.

This function determines if the first character in the specified string is a number. If it is, it parses the string until it reaches the end of the number, and returns the number as a number, not as a string.

Eg:

var float1= parseFloat(“12.67”);

console.log(float1); // 12.67

var float2= parseFloat(“45 90 12”);

console.log(float2); // 45


8. isNan():

This function determines whether a value is NaN (Not-A-Number) or not.

Eg:

var nan1= isNan(“3435”);

console.log(nan1); // false

var nan2= isNan(“test”);

console.log(nan2); // true


9. eval():

This function evaluates JavaScript code represented as a string.

The argument of the eval() function is a string. If the argument of eval() is not a string, eval() returns the argument unchanged.

var a = 5;

var b= 2;

var res= eval(“x * y”);

console,log(res); // 10

I found these are interesting and much useful!! Please let me know your thoughts…

Comments

Popular Posts