Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to get user data in my Rails app.

I am doing this:

  url_so = ""
  curl =
  data_obj = JSON.parse(curl.body_str)

But, the JSON parser says its not a correct format. So, when I did a curl.body_str , I got this.

 => "\037\213\b\000\000\000\000\000\004\000\354\275\a`\034I\226%&/m\312{\177J\365J\327\340t\241\b\200`\023$\330\220@\020\354\301\210\315\346\222\354\035iG#)\253*\201\312eVe]f\026@\314\355\235\274\367\336{\357\275\367\336{\357\275\367\272;\235N'\367\337\377?\\fd\001l\366\316J\332\311\236!\200\252\310\037?~|\037?\"~\361o\234\244\351Gm\325f\345G\217\322\335\021\377\271\312.\362\360\257\246\370\001>\271\267#\037\255\233\274n\350\357\357\341\2574\375\305\362C\277\370\375\213\031}\265wo\367\341\356\203Q\370M{\275\002\230\217\352\374\242h\332\274\316g\037\271\026\323:\317\332\242Z\376.......

Any suggestions? How can I fetch a JSON file?

I am new to Ruby on Rails too, so is there any better gem to access the SO API?


This works, the problem was it was GZIP

  curl =
  json_data = ActiveSupport::Gzip.decompress(curl.body_str)
share|improve this question
@sys: Why? This relates to the API. – Nathan Osman Aug 9 '10 at 7:05
up vote 2 down vote accepted

I think your problem is that you're forgetting that the API only supplies gzipped data.

I don't use Ruby, so you'll have to figure out how to tell curl to accept gzip data.

share|improve this answer
Oh yeah, I'd already forgotten this. This caused me a huge nightmare when I first set out on the API. – Mark Henderson Aug 9 '10 at 21:26
Link: – zengr Dec 4 '11 at 23:16

Try to set the Accepted-encoding like:

curl =
curl.headers["Accept-Encoding"] = "gzip,deflate"
share|improve this answer
didn't try this, but this also might work. – zengr Aug 9 '10 at 7:07
@zengr give it a shot :) – systempuntoout Aug 9 '10 at 7:14

Try it without the ?type=jsontext parameter.

share|improve this answer
tried it, does not help – zengr Aug 9 '10 at 6:05
Same code works like a charm on github API: ""; + github_id – zengr Aug 9 '10 at 6:05

Are you doing this to learn ruby, or get a Stack Apps app up and running?

If you're looking to just get an app up, try one of these libraries - make life easier for yourself :)

If you're looking to learn ruby (and thus don't want to use a library), well I've never used ruby so I can't help.

share|improve this answer

From this link: Gzip and deflate compression in curb http driver

You can set curl.encoding = '' to make curb auto decompress response body. Like below:

url_so = ""
curl =

# enables both deflate and gzip compression of responses
curl.encoding = ''

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .