You can parse this to a dictionary that maps keys to a list of values:
from urllib.parse import parse_qs
data = parse_qs('username=andrew&password=password1234')
this will give us:
>>> parse_qs('username=andrew&password=password1234')
{'username': ['andrew'], 'password': ['password1234']}
This is because a key can occur multiple times. If you are sure it only occurs once per key, you can use dictionary comprehension to convert it to a single item:
from urllib.parse import parse_qs
data = { k: v
for k, vs in parse_qs('username=andrew&password=password1234').items()
for v in vs
}
and this produces:
>>> { k: v
... for k, vs in parse_qs('username=andrew&password=password1234').items()
... for v in vs
... }
{'username': 'andrew', 'password': 'password1234'}
You can make use of json.dumps(…)
[python-doc] to convert it to a JSON blob:
>>> print(dumps(data))
{"username": "andrew", "password": "password1234"}