What Is JSON?

In this video, you’ll learn what JSON is and where it’s used.

JavaScript Object Notation (JSON) is a standardized format commonly used to transfer data as text that can be sent over a network. It’s used by lots of APIs and Databases, and it’s easy for both humans and machines to read.

JSON represents objects as name/value pairs, just like a Python dictionary.

You can start using JSON right away with the built-in module:

import json

Serialization is the process of encoding data into JSON format (like converting a Python list to JSON).

Deserialization is the process of decoding JSON data back into native objects you can work with (like reading JSON data into a Python list).

00:00 Hi! I’m Austin Cepalia with realpython.com, and today we’re going to learn how to work with JSON data in Python. In this video, we’ll start by learning about what JSON is and what it’s used for.

00:14 JSON stands for JavaScript Object Notation. It was inspired by a subset of the JavaScript language dealing with object literal syntax, but nowadays it’s completely independent of JavaScript, and lots of languages support it. JSON is a standardized format commonly used to transfer data.

00:33 There’s no way to easily transfer native Python objects over the internet, and that’s why we have JSON. XML and YAML are other standards used for similar purposes, so if you’ve worked with those before, then you’ll find the process of working with JSON data to be pretty familiar.

00:49 JSON is frequently used in databases and APIs. We can use it when we need to retrieve information from our own servers or even an API that exposes a public endpoint. As we’ll see in a moment, many APIs return data in JSON format, and we can use that data within our own programs.

01:08 JSON is popular because it’s easy for both humans and machines to read. So, who uses JSON? And what can you do with it? Well, for one, it’s used by YouTube to deliver information about accounts, videos, and video searches. It’s also used by other big names like Twitter for interacting with tweets, Google Maps for getting map data, and NASA for public data and imagery.

01:32 It should be noted that there are limitations to how you use this data, as well as how much of it you can request. But nonetheless, it’s still really cool. Understanding how JSON works in Python will allow you to create your own applications that interface with others.

01:49 This right here is what JSON looks like. If you take a step back and observe the syntax, you’ll notice that it actually looks kind of like a Python dictionary.

01:58 It uses key-value pairs. So in this example, "name" is a key and "Jane Doe" is the associated value. JSON supports primitive types like strings and numeric types, as well as nested arrays and objects.

02:14 You can also see that JSON supports indentation. However, unlike Python, JSON doesn’t require indentation. It’s very common to see JSON presented in a minified form without indentation.

02:27 And as we’ll see later on, it’s easy to generate JSON data with indentation baked in so it’s easy for us to read.

02:34 Let’s take a look at a common scenario for working with JSON data. Imagine that we’ve written an API that gives us statistical data in JSON format. We need to use this data in a different application of ours and, lucky for us, Python makes that possible. We’ll make a request to our web API for our data, and that will come back in JSON format.

02:56 It might give us more than we need, so we can have our Python program filter out the data that we don’t need and manipulate it in some other way if we want.

03:05 We can represent JSON data in the form of native Python objects like lists and strings, which means that we can use the data with a library—like matplotlib—in order to graph it and display it on the screen. Finally, we can store this data in our own database somewhere by packaging the Python objects into JSON format and then sending it off to our own database.

03:29 This is one way we can make use of JSON. Python makes it easy to work with JSON data. It’s got a built-in module called json that exposes functions for working with data, like dump() and load().

03:42 But in order for us to start using these functions, we have to understand how to read and write JSON data first.

03:50 There’s two important words to know here: serialization and deserialization.

03:56 We’ll be using these words heavily throughout the rest of this course, so it’s important to understand what they mean. When we take some data in our Python program and encode it into JSON format, that’s called serialization.

04:10 When we take some JSON data and convert it back into native data that we can use in our programs—like a Python list, for example—that’s called deserialization.

04:21 Think of it like reading and writing with files. Encoding is like writing to a file and decoding is like reading from one. The only difference is we can’t simply write and read our Python objects.

04:34 They must be serialized into JSON format and then deserialized back into Python objects. In the next video, we’ll learn how to serialize Python data into JSON format.

Avatar image for Brett Boresow

Brett Boresow on April 14, 2019

Solid overview!

Avatar image for Ashish

Ashish on Jan. 14, 2020

HI. Video not getting loaded after 2 minute 10 seconds on page realpython.com/lessons/what-is-json/

Is there some video file issue?

Avatar image for Dan Bader

Dan Bader RP Team on Jan. 15, 2020

Hi Ashish, the video seems to load and play fine for me and I’m also seeing in the server logs that it’s working for others. This might be a browser or connectivity issue on your end. We’ve got this video troubleshooting support article in our knowledge base that should help you get it resolved. If those tips don’t work please send us an email at info@realpython.com and we’ll debug it together :) Best, Dan

Avatar image for Ashish

Ashish on Jan. 15, 2020

Thanks Dan. It’s working for me now. Could be a temporary glitch.

Regards Ashish

Avatar image for Roy Telles

Roy Telles on April 11, 2020

Is it possible to upload transcripts to video lessons? Sometimes I’m not in the best situation to listen to audio but would still like to take notes while following along :) thanks!

Avatar image for Anubhav P

Anubhav P on Aug. 16, 2023

I am unable to download supporting material (slides)

Become a Member to join the conversation.