Bender
Bender

Reputation: 69

JSON obtain value from key in Python

I have this Python script:

import json
from cinbase.walle.client import Client

apiKey = foo
mysecret = bar

client = Client( apiKey, mySecret )
price = client.get_spot_price(currency_pair = 'BTC-EUR')

This is my output:

{
"data" :{
             "amount": "123455"
             "currency": "EUR"
 }
}

How to get only "amount" value?

Upvotes: 1

Views: 84

Answers (1)

ahammond
ahammond

Reputation: 31

In python, this data type is called a dict (short for dictionary). You can index this object as follows:

value = your_dict[key]

So in your case specifically:

amount = price["data"]["amount"]

Upvotes: 2

Related Questions