简体   繁体   中英

extract specific json values from url and put as array

I want to extract specific values from Alpha Vantage API and want to display in a Sparkline chart.

I have a JSON file like -

    {
        "Meta Data": {
            "1. Information": "Intraday Prices and Volumes for Digital Currency",
            "2. Digital Currency Code": "BTC",
            "3. Digital Currency Name": "Bitcoin",
            "4. Market Code": "EUR",
            "5. Market Name": "Euro",
            "6. Interval": "5min",
            "7. Last Refreshed": "2018-05-05 09:30:00",
            "8. Time Zone": "UTC"
        },
        "Time Series (Digital Currency Intraday)": {
            "2018-05-05 09:30:00": {
                "1a. price (EUR)": "8213.91934125",
                "1b. price (USD)": "9833.29603162",
                "2. volume": "14118.15104183",
                "3. market cap (USD)": "138827958.61346000"
            },
            "2018-05-05 09:25:00": {
                "1a. price (EUR)": "8205.43730260",
                "1b. price (USD)": "9823.14175648",
                "2. volume": "14138.79003689",
                "3. market cap (USD)": "138887338.79747999"
            }
           .
           .
           .
        }
   }

I want to extract only "1b. price (USD)": "9833.29603162" this values and put them is a JS array

var myvalues = [9833.296,9823.141,...];

I am using to do some other tasks. Please help!

If you want to extract specific data using JSON you can use the code below. For each library you need to change the function. The names of the library and what Function name you need to use is in the alpah vantage documentation.

https://www.alphavantage.co/documentation/#

    ### FUNADMENTAL DATA > COMPANY OVERVIEW ###
    # https://www.alphavantage.co/query?function=OVERVIEW&symbol=IBM&apikey=demo

base_url = 'https://www.alphavantage.co/query?'
params = {'function': 'OVERVIEW',
         'symbol': stock_ticker,
         'apikey': keys}
response_data_overview = requests.get(base_url, params=params)

data_overview_Name = response_data_overview.json()['Name']
data_overview_AssetType = response_data_overview.json()['AssetType']
data_overview_Description = response_data_overview.json()['Description']
data_overview_Exchange = response_data_overview.json()['Exchange']
data_overview_Currency = response_data_overview.json()['Currency']
data_overview_Country = response_data_overview.json()['Country']
data_overview_Sector = response_data_overview.json()['Sector']
data_overview_Industry = response_data_overview.json()['Industry']
data_overview_Address = response_data_overview.json()['Address']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM