jonathanbell
jonathanbell

Reputation: 2637

How to send headers from YQL in order to return JSON format when querying opendatabc API?

I'm wondering if there is a way to send headers from YQL (or the YQL console) like there is in cURL.

I would like to return JSON by specifying the header Accept: application/json.

I am able to return JSON in with cURL and the command line like this:

curl -H 'Accept: application/json' http://www.opendatabc.ca/data?=births

but I can't figure out how to set the header when sending YQL.

Upvotes: 1

Views: 1204

Answers (3)

Chan
Chan

Reputation: 914

use "jq", if have not installed it yet, run this command first sudo apt-get install jq

then you can curl your url like this

curl -H 'Accept: application/json' http://www.opendatabc.ca/data?=births | jq '.'

Upvotes: 0

kenorb
kenorb

Reputation: 166813

You should use format parameter when querying YQL over API, instead of headers. Either by format=json or format=xml.

JSON example:

curl -G --data-urlencode 'q=SELECT * FROM html WHERE url = "example.com"' http://query.yahooapis.com/v1/public/yql?format=json

XML example:

curl -G --data-urlencode 'q=SELECT * FROM html WHERE url = "example.com"' http://query.yahooapis.com/v1/public/yql?format=xml

Upvotes: 0

swook
swook

Reputation: 478

You can do this with YQL Open Data Tables.

Here is a simple demonstration.

You can find the gist for the example Open Data Table XML file here: https://gist.github.com/2042904 (Check out the documentation here.)

You will notice in my example XML that I'm using y.xmlToJson on the response object received from the get() request. This is because YQL converts JSON taken from web services into E4X. More about that in a question of mine.

Upvotes: 1

Related Questions