How to post JSON data with null as value in python request

Viewed 9145

I have JSON data which which needs to formated and sent to the server with null values set as null. A dictionary in Python cannot have null as value but can have "null" as a value. How do I convert the above to a dictionary that Python recognizes?

a = {"name":"p_retailprice","type":"DOUBLE","comment":"","precision":null,"scale":null}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'null' is not defined
1 Answers

The equivalent of the null keyword in Python is None.

Try

a = {"name":"p_retailprice","type":"DOUBLE","comment":"","precision":None,"scale":None}
Related