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.

Parsing and serializing JSON

Parsing and serializing JSON - Python Tutorial

From the course: Python: XML, JSON, and the Web

Start my 1-month free trial

Parsing and serializing JSON

- [Instructor] All right, let's try working on a real JSON example. And here in VS code, I'll open up JSON underscore parse underscore start dot py. And, to work with JSON, I first have to import the JSON module into my program. So I'll write import JSON. And you can see that I've already defined a string here containing some JSON formatted data. So we're going to do two things. First, we'll parse this JSON data into a Python object. And then, we'll access some of the data in that object. So, to parse this data, I'm going to use the load S function, since I already have the data in a string. Now, in a real app, this data could be coming from a file, or from a call to the Requests library, or some other data source. So I'll write data equals JSON dot load S. And I'll just pass the JSONStr that I have right here. And this will build a native Python dictionary object for me. So once I have that object, I can then work with it like any other Python dictionary. So first, let's go ahead and…

Contents