Design question for RESTful APIs: one of the input parameters to my API (that is, the data sent from the client to my API) is a dictionary (hash / key-value pairs). What's the best way to encode this so that the API can be easily invoked from web pages as well as scripts/programming languages?
My first thought was to json encode the object, something like this:
var data = {a:'one', b:'two'};
form_paramter_x = JSON.stringify(data);
and decode on the server:
data = simplejson.loads( request.POST['form_paramter_x'] )
The alternative would be to encode as key-value pairs html-form-checkbox style:
form_param_x=a:one&form_param_x=b:two
The latter alternative would require ad-hoc parsing of the key and value (the "a:one" part), and generally seems less clean, but also seems closer to a basic HTML form, which is probably a good thing.
Which of these is cleaner? Or is there another better alternative?