I have a list of tuples which are http headers. I want to convert the list to a JSON object. I try mochijson2 but to no avail.
So I have the following :
[{'Accept',"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},
{'Accept-Charset',"ISO-8859-1,utf-8;q=0.7,*;q=0.7"},
{'Accept-Encoding',"gzip,deflate"},
{'Accept-Language',"en-us,en;q=0.5"},
{'Cache-Control',"max-age=0"},
{'Connection',"close"},
{'Cookie',"uid=CsDbk0y1bKEzLAOzAwZUAg=="},
{'User-Agent',"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"}]
And would like this ( a binary JSON string ) :
<<"{\"Accept\":\"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\",
\"Accept-Charset\":\"ISO-8859-1,utf-8;q=0.7,*;q=0.7\",
\"Accept-Encoding\":\"gzip,deflate\",
\"Accept-Language\":\"en-us,en;q=0.5\",
\"Cache-Control\":\"max-age=0\",
\"Connection\":\"close\",
\"Cookie\":\"uid=CsDbk0y1bKEzLAOzAwZUAg==\",
\"User-Agent\":\"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10\"}">>
And I try this where A is the original list of tuples :
list_to_binary(mochijson2:encode(A)).
I suspect I need to get it into a format that mochijson2 can interpret better. And then convert to binary. Or figure out a way to have all the characters represented as strings (rather than have some as list of integers).
Greatly appreciated if you could point me in the right direction with some sample code.