url quoting required for json body?

27 views
Skip to first unread message

Eric Rasmussen

unread,
Oct 11, 2012, 2:44:55 PM10/11/12
to mailchimp-...@googlegroups.com
Hi,

I'm trying to figure out how you parse json requests. It looks like when I POST requests the headers are ignored (content-type: application/json), and the json body is unquoted prior to parsing. Is this a safe assumption?

As an example, if my request body is a json object along the lines of:
    { "id":"my list id","email_address":"special+...@example.com"}

It should first be url quoted as:
    %7B%22id%22%3A%22mylistid%22%2C%22email_address%22%3A%22special%2Bcharacter%40example.com%22%7D

You would then unquote the body, parse the json, and proceed. Correct?

The puzzling part is that except for the "+" character, quoting seems to have no bearing on how you parse the response. I can't imagine what it's doing on your side such that quoting is optional for some characters and not others, and any clarification would be much appreciated.

Thank you!
Eric

jesse

unread,
Oct 11, 2012, 2:55:10 PM10/11/12
to mailchimp-...@googlegroups.com
Quoting is a misnomer here - it looks like you're doing html character encoding, not urlencoding. Take a look at example #2 here:
http://apidocs.mailchimp.com/api/1.3/listsubscribe.func.php


jesse

Eric Rasmussen

unread,
Oct 11, 2012, 3:21:34 PM10/11/12
to mailchimp-...@googlegroups.com
Thanks. The php urlencode function seems to behave similarly to the python urllib.quote function. But regardless of whether we call it quoting, escaping, or encoding, as long as I understand it's required I can move forward.

For the record though I still don't understand *why* it's required. In that example you linked me to there should be no reason to call urlencode() on the json body. The application/json content-type header exists so the server can decode it as json, not decode the body separately as url encoded and then decode json. I've worked with a number of major APIs before and this is the first time I've ever seen the json body treated this way.
Reply all
Reply to author
Forward
0 new messages