March 2019
Beginner
490 pages
12h 40m
English
We use the json module for working with JSON in Python. The json package allows you to transform a Python object into a character string that represents those objects in JSON format. Let's create a json representation of a Python list by using the following commands:
>>> import json>>> books = ['book1', 'book2', 'book3']>>> json.dumps(books)'["book1", "book2", "book3"]'
The json.dumps() function allows you to transform a dictionary-type object as the first parameter into a text string in JSON format. In this case, we can see the JSON string appears to be identical to Python's own representation of a list, but note that this is a string. You can confirm this by executing the following commands:
Read now
Unlock full access