JSON

JavaScript Object Notation (JSON) is a standard way of representing simple objects, such as lists and dicts, in the form of text strings. Although, it was originally developed for JavaScript, JSON is language independent and most languages can work with it. It's lightweight, yet flexible enough to handle a broad range of data. This makes it ideal for exchanging data over HTTP, and a large number of web APIs use this as their primary data format.

Encoding and decoding

We use the json module for working with JSON in Python. Let's create a JSON representation of a Python list by using the following commands:

>>> import json
>>> l = ['a', 'b', 'c']
>>> json.dumps(l)
'["a", "b", "c"]'

We use the json.dumps() function for converting an object to ...

Get Learning Python Network Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.