'How to urlencode a json payload with empty key values and parse it to get the original payload
All I'm trying to do is urlencode the payload and then parse it to get what I originally started with.
payload = {"contact_uuid": "67460e74-02e3-11e8-b443-00163e990bdb", "choices": None, "value": "", "cardType": "", "step": None, "optionId": None, "path": "", "title": "", "description": "", "message": ""}
urlencode(payload) returns:
contact_uuid=67460e74-02e3-11e8-b443-00163e990bdb&choices=None&value=&cardType=&step=None&optionId=None&path=&title=&description=&message=
Notice the empty strings are lost
When I try to parse it back to the original json it doesn't work (variable name is encoded_url)
body = (parse_qs(encoded_payload))
print(body) returns:
{'contact_uuid': ['67460e74-02e3-11e8-b443-00163e990bdb'], 'choices': ['None'], 'step': ['None'], 'optionId': ['None']}
Please how can I urlencode the original payload without losing empty key values and then parse it to get the original json payload. I also do not want the lists. I just want the exact json form I started with. NB - It doesn't have to be urlencode or parse libraries. Other solutions are welcome. Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
