Skip to main content
Colin Jaffe/3 min read

Navigating and Extracting Specific Data from an API Response

Parse an API Response

1

Inspect the Shape

Log the response — JSON nesting can be deep and inconsistent.

2

Drill with Dot Notation

data.results[0].user.email — chain accessors to your value.

3

Use Optional Chaining

data?.user?.email — safely handle missing keys without crashing.

4

Map Arrays

results.map(r => ({ id: r.id, name: r.full_name })) — reshape for your UI.

Master Full Stack Development at Noble Desktop

Noble Desktop's Full-Stack Web Development Certificate covers HTML, CSS, JavaScript, and the modern web stack.

This lesson is a preview from our Data Science & AI Certificate Online (includes software) and Python Certification Online (includes software & exam). Enroll in a course for detailed lessons, live instructor support, and project-based training.

Navigate the nested Python dictionary to access stock closing data for a specific date. Watch this tutorial to learn the key concepts and techniques.

Let's take a look at how we might go about solving this question—this challenge. How do we print out the data for a specific date? Remember, this is all data we got back from an API—data we got essentially for free—and we can find all kinds of information in it. Let's give it a try.

If I just print out the data, or technically output the data, it's a very, very big dictionary. In fact, it's going to take me a while even just to scroll to the top. We can see there's just a massive amount of keys, values, and dictionaries in here. If you're not terribly used to navigating dictionaries, objects, and things like that, this might be a little tough for you, and you might feel a bit overwhelmed.

Fortunately, Python—and pretty much any programming language worth its salt—has some tools for quickly understanding this dictionary we're looking at. One of the helpful ones in Python is .keys(). If we look at that, it gives us just a list of the keys we could access here. "Meta Data" is one, "Time Series (Daily)" is the other.

Let's just print those out—keys in data. There it is. So let's take a look at what "Meta Data" is.

It's a dictionary, just like data is, and the keys are: information, symbol, last refreshed, output size, time zone. The value for each key is a string. We have information about it, and that's helpful metadata, but we want actual data—not data about our data, which is what metadata is. So the other option was "Time Series (Daily)."


Let's try that one out. I was hoping to get some autocomplete with that. I didn't.

Let's try that. All right, this is, again, a lot of data—but maybe this is the data we want: this "Time Series (Daily)" object. Let me scroll up and up and up through all of this to get a sense of how it starts.

It looks like what we're looking at—data["Time Series (Daily)"]—is an object. It starts right with a curly brace, and each key is a date. The value for each date key is another dictionary. A dictionary within a dictionary, within another dictionary.

If we want a specific date, well, that looks like our next level down. Let's try the date we're looking for—and there it is. That's actually our answer for the challenge.


If we want to take it a step further, let’s say we want to actually find out, you know, what value did Apple close at on that day? Well, we can look at the next level, because the "Time Series (Daily)" key at this date is a dictionary, and it itself has keys—one of them is "4. close". And here we are. Here's our value: $217.90, which was the closing value for Apple on March 28th of this year. We can see all kinds of information in our API, and honestly, it’s given us so much valuable information that the challenge is really just navigating it at this point.

All right, that's our challenge. We'll go on to putting it in a Pandas DataFrame and looking at it from there.