From the course: Using Python for Automation (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Parsing through JSON

Parsing through JSON

- [Instructor] So I've built the API request to the UPCitemdb interface, and now it's time to work with the API's response. Let's begin by grabbing the response's content attribute, as this will contain the content sent back from the website's interface. (typing) Recall that APIs transfer information in the form of JSON documents, which is not a native data structure in Python. So to make the response more navigable, let's go ahead and import a library called JSON. This will help, as JSON has a function called loads that converts JSON documents into dictionaries, thus making the API's response much more Python-friendly. (typing) To confirm that the function has worked correctly, I'll go ahead and check the info's data type, as well as print it to the console. (typing) Great, our suspicions are confirmed, as the type is, indeed, a dictionary, so we're now ready to isolate the specific data. Looking back at the online GUI, let's try isolating the item's name as…

Contents