I am trying to update an existing dictionary with a new key-value pair.But the update dictionary adds single quotes to the value field. This dictionary is to be used for mongo query and hence needs to be clean of additional quotes whenever I substitute the value variable in dictionay.update(key:value)
I tried using eval and json.loads. But that was not fruitful. Any advices please.
mquery ={"type" : "search"}
skey = "ZXCV,YBC"
skey = '{"$in": [/' + skey.replace(',','/,/') + '/]}'
print(skey)
if skey is not None : mquery.update({"skey1" : skey})
print(mquery)
Expected - {'type': 'search', 'skey1': {"$in": [/ZXCV/,/YBC/]}}
Current - {'type': 'search', 'skey1': '{"$in": [/ZXCV/,/YBC/]}'}