I have a payload in my request against an endpoint having values null and true. In Pycharm I get red-dotted line below the two respectively. How can I “define null and true inside my json payloads setmethod in Python?
def setpayload_set():
myjson = {
"hpsId": 10034,
"powerPlants": null,
"units": [{"componentId": 78111,
"timeSeries": [{"name": "ts.start_bids_allowed",
"dtssId": "", "tsv": {"pfx": true,
"data": [[1723647600,
1]]}}]}]
}
return myjson
0
In python you should use None
istead of null
and True
istead of true
in your JSON-like dictionary.
def setpayload_set():
myjson = {
"hpsId": 10034,
"powerPlants": None,
"units": [
{
"componentId": 78111,
"timeSeries": [
{
"name": "ts.start_bids_allowed",
"dtssId": "",
"tsv": {
"pfx": True,
"data": [
[1723647600, 1]
]
}
}
]
}
]
}
return myjson
but if you wont to put null
and true
as the values then convert the python dictionary to Json string.
import json
json_payload = json.dumps(setpayload_set())
print(json_payload)