How to Handle JSON NULL in Python
There is no NULL in Python. Instead, it has None. JSON has a NULL data type, but it has not a None data type. A dictionary in Python cannot have null as a value but can have “null” as a value that can be interpreted as a string.
Handle JSON NULL in Python
To handle the JSON NULL in Python, use the json.loads() method. The loads() method returns the null equivalent of Python, which is None.
To work with json data in Python, import the json library. Then define a json object consists of a null value, which we will convert into None.
import json data = '{ "name":"WandaVision", "service":null }' # parse the data dict = json.loads(data) print(dict)
Output
{'name': 'WandaVision', 'service': None}
And you get the None value, which is equivalent to null in json.
This is the way you can handle the null value of JSON in Python.