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

How to easily locate your JSON object in your API response?

 Dear People,

I hope you are safe and doing good.

When I started with API Testing, JSON format was quite new to me. But somehow I liked it due to it’s readability. Due to the love for that, currently I have updated my bio in many places in JSON format. Okay, let me explain why I am writing this post.

  1. Personally I, myself faced lot of challenges in parsing the bigger JSON response of an API
  2. In Postman community forum, I see many people asking about the error “undefined”. This pops-up when the JSON path is invalid (can be in your Test cases or trying to assign a value from the response to a variable or when you are trying to print the JSON object). In all these cases, if the path mentioned to reach the JSON element is wrong then it returns “undefined”.

How to fix this?

This is a very common error, when we are dealing with API requests and responses. For JSON responses, we have a simple tool where we can just paste our response and the tool helps us to reach the desired element, particularly where there’s nested arrays involved. This tool is developed by Joe Beach. This is the GitHub URL.

Let’s see with an example. This tool as such have an example displayed to help us understand how it works:

Step 1:

Launch the URL (https://jsonpathfinder.com/)

Step 2:

If you have your response, you can paste it directly by clearing the left hand side. Else if you are planning to explore it, click “Sample”.

Step 3:

Now in the right hand side, you can see the response hierarchy. Try to expand them.

Step 4:

For example, if I need to reach the language “Hindi”, I will be clicking the language field on the right side. The Path field at the top gives you the exact path to reach the key “Hindi”.

So in your postman scripts,

var resp = pm.response.json();

You will be parsing the entire response and storing it in a variable right? Instead of x in the path, replace it with the variable which you created for storing the parsed response.

x[“Indo-European”][“Indo-Iranian”].Indic[3]

as

resp[“Indo-European”][“Indo-Iranian”].Indic[3]
console.log(resp[“Indo-European”][“Indo-Iranian”].Indic[3]); // “Hindi”

Tada!! That’s it, you get what you wanted.

Same way you can copy your entire response and paste it here, and try to reach the element you want. This is a pretty easy approach, and once you learn the basics of JSON, you can try to print the element and see in the console how to reach the key which you need in the response.

For newbies, this will definitely helpful and it reduces much of your debugging time!!

I hope you learnt something interesting today!

See you in my next post!

--------------------------------------------------------------------------------------------------------------------------------------

Originally published in https://bpricilla.medium.com/how-to-easily-locate-your-json-object-in-your-api-response-647549ee8b2

Comments

Popular Posts