json - add a variable conditionally in python code -
i new python , wondering in below python code how add variable conditionally.
requestbody = json.dumps({"accountid":accountid, "emailsubject":customdata.emailsubject, "emailblurb":customdata.emailblurb, "customfields":customfields, "status":customdata.status, "messagelock":customdata.messagelock})
like example want "custom"fields:customfields
included if not null else not.how this??
create dictionary , add keys it, dump it. general way of doing things allows use different logic each key (e.g. if given key > 10
).
to_json = {"accountid":accountid, "emailsubject":customdata.emailsubject, "emailblurb":customdata.emailblurb, "customfields":customfields, "status":customdata.status, "messagelock":customdata.messagelock} if james not none: to_json['james'] = james requestbody = json.dumps(to_json)
Comments
Post a Comment