From the course: Python: XML, JSON, and the Web
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Requests and JSON - Python Tutorial
From the course: Python: XML, JSON, and the Web
Requests and JSON
- [Instructor] Before we move on from the subject of JSON, I want to quickly demonstrate one of the convenience methods for working with JSON that the requests library provides. And since the pattern of retrieving JSON text and parsing it into a native dictionary is fairly common, the requests library will automatically detect if the returned content from a request is JSON and will parse it for you. The data is then made available using the JSON function. So here in my code for JSON req start dot py, I'm going to request some data from the JSON endpoint at httpbin, which I know returns some valid JSON code. To access the parsed data, I just need to use the JSON function. So lemme go ahead and do that, and I'll need my variable data object, and I'll just simply call result dot JSON. And of course, we can go ahead and print this out just to make sure it works, and I'm going to use the dump s function to dump out data object and give it an indentation of four. And of course, I can access…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.