JSON in Python

Coding with Python

🕑 This lesson will take about 20 minutes

JSON, which stands for JavaScript Object Notation, is a data-interchange format that is commonly used for transmitting data between a server and an application, as well as for storing configuration settings and other structured data. JSON is easy for both humans and computers to read and write. JSON is language-independent, meaning it can be used with many programming languages, not just JavaScript.

JSON data is organised into key-value pairs, similar to how dictionaries are represented in Python (or how objects are represented in JavaScript and other languages). JSON-formatted data can be stored as a string (eg. in a variable, a field in a database, or in a file). As JSON data is organised this way, it makes it easy to take JSON data (eg. from a database or web server) and convert it into a Python dictionary, or to convert a Python dictionary into JSON data that can be transmitted (eg. to a database or web server). In the next lesson, we will look at how JSON is used when fetching data from a web API.

Here is some sample code showing how to read data that is formatted in JSON format, and how to write data in JSON format.

Next lesson: Web requests