Another question about JSON

John Gordon gordon at panix.com
Fri Sep 13 10:35:00 EDT 2013


In <mailman.355.1379077258.5461.python-list at python.org> Anthony Papillion <papillion at gmail.com> writes:

> I'm still working to get my head around JSON and I thought I'd done so
> until I ran into this bit of trouble. I'm trying to work with the
> CoinBase API. If I type this into my browser:

> https://coinbase.com/api/v1/prices/buy

> I get the following JSON returned

> {"subtotal":{"amount":"128.00","currency":"USD"},"fees":[{"coinbase":{"amount":"1.28","currency":"USD"}},{"bank":{"amount":"0.15","currency":"USD"}}],"total":{"amount":"129.43","currency":"USD"},"amount":"129.43","currency":"USD"}

> So far, so good. Now, I want to simply print out that bit of JSON (just
> to know I've got it) and I try to use the following code:

> returnedJSON = json.loads('https://coinbase.com/api/v1/prices/buy')
> print returnedString

JSON is a notation for exchanging data; it knows nothing about URLs.

It's up to you to connect to the URL and read the data into a string,
and then pass that string to json.loads().

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list