2

I want to download the JSON data from this sample API call into a file.

I tried using wget, like so:

wget -O ~/ks/json.txt "http://api.stackexchange.com/2.2/search/advanced?pagesize=5&fromdate=1420761600&todate=1420934400&order=desc&sort=activity&accepted=True&answers=1&tagged=hadoop&site=stackoverflow&filter=withbody"

The output I get is not in readable format. The same command works for other web services. Is the Stack Exchange API restricting something or am I doing it wrong?

1 Answer 1

4

The API documentation states that the API always returns a compressed response:

...we guarantee that all responses are compressed, either with GZIP or DEFLATE.

GZIP is the default.

This means that you must send the results from wget to gunzip. Like so:

wget -O- <URL> | gunzip > results.json

Or, in your specific example:

wget -O- "http://api.stackexchange.com/2.2/search/advanced?pagesize=1&fromdate=1420761600&todate=1420934400&sort=activity&accepted=True&answers=1&tagged=hadoop&site=stackoverflow&filter=withbody" | gunzip > ~/ks/json.txt
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.