Couch parameter values are JSON literals, so should be created by JSON-encoding the values. Then you need to URL-encode the results of that to fit in a standard URL, as well.
Example:
import urllib, json
def to_json_query(params):
return urllib.urlencode({p: json.dumps(params[p]) for p in params})
>>> qs = to_json_query({'descending': True, 'startkey': 'Mexico', 'endkey': 'Mexico'})
'startkey=%22Mexico%22&endkey=%22Mexico%22&descending=%22true%22'
Note I have changed the value of descending
to be a boolean True
, as you want a JSON boolean true
and not the string "true"
.
(The existing answers here assume string and don't URL-encode or JSON-encode, so will fail for any JSON-special or URL-special characters, any non-ASCII or non-string datatype.)