Extreme API with Python

Table Of Contents
Extreme API with Python
Page | 16
Part no.9036931-00 Rev AA February 2021
information that can be read by humans, JSON is currently the most efficient tool. Nevertheless, when
you need to exchange a vast amount of information, performance and efficiency become more
important and you can consider new standards. These alternatives are not yet used in external Extreme
APIs, although binary formats, such as Protobuf, are becoming popular as well. JSON and Protobuf are
expected to co-exist, serving different needs.
2.5 Manipulating JSON with Python
Manipulating JSON-formatted data with Python is simple because the data types are well matched. The
standard library, included by default with Python, has a JSON module that converts JSON to Python, and
vice-versa, as defined in the Python documentation, and shown in this table:
JSON
Python
Object dict
Array list
String str
number (int) int
number (real) float
true True
false False
null None
HTTPS://docs.python.org/3/library/json.html#encoders-and-decoders
View the functions and methods available with JSON using the print(dir(json)) command:
import json
print(dir(json))
The result:
['JSONDecodeError', 'JSONDecoder', 'JSONEncoder', '__all__', '__author__',
'__builtins__', '__cached__', '__doc__', '__file__', '__loader__',
'__name__', '__package__', '__path__', '__spec__', '__version__',
'_default_decoder', '_default_encoder', 'codecs', 'decoder',
'detect_encoding', 'dump', 'dumps', 'encoder', 'load', 'loads', 'scanner']
The methods most often used are highlighted in this example. The following examples illustrate how to
use some of these methods.