0

I have the json data below. How do I select the open value of 2020-11-06 19:50:00 and use a console.log() to log it to the console?

{
    "Meta Data": {
        "1. Information": "Intraday (5min) open, high, low, close prices and volume",
        "2. Symbol": "IBM",
        "3. Last Refreshed": "2020-11-06 20:00:00",
        "4. Interval": "5min",
        "5. Output Size": "Compact",
        "6. Time Zone": "US/Eastern"
    },
    "Time Series (5min)": {
        "2020-11-06 20:00:00": {
            "1. open": "114.4400",
            "2. high": "114.4400",
            "3. low": "114.4400",
            "4. close": "114.4400",
            "5. volume": "457"
        },
        "2020-11-06 19:50:00": {
            "1. open": "114.4000",
            "2. high": "114.4000",
            "3. low": "114.3300",
            "4. close": "114.3300",
            "5. volume": "648"
        }
    }
}
Trekco
  • 1,246
  • 6
  • 17
w-tb
  • 3
  • 2
  • Can you provide some of your code you are more likely to get an answer if you show what you have tried and helps us understand your issue better and what you might be misunderstanding. – Fletcher Rippon Nov 09 '20 at 04:04

1 Answers1

0

You 1st need to assign it to a variable, then you should be able to access like below

var jsonData = {
    "Meta Data": {
        "1. Information": "Intraday (5min) open, high, low, close prices and volume",
        "2. Symbol": "IBM",
        "3. Last Refreshed": "2020-11-06 20:00:00",
        "4. Interval": "5min",
        "5. Output Size": "Compact",
        "6. Time Zone": "US/Eastern"
    },
    "Time Series (5min)": {
        "2020-11-06 20:00:00": {
            "1. open": "114.4400",
            "2. high": "114.4400",
            "3. low": "114.4400",
            "4. close": "114.4400",
            "5. volume": "457"
        },
        "2020-11-06 19:50:00": {
            "1. open": "114.4000",
            "2. high": "114.4000",
            "3. low": "114.3300",
            "4. close": "114.3300",
            "5. volume": "648"
        }
    }
};

console.log(jsonData["Time Series (5min)"]["2020-11-06 20:00:00"]["1. open"]);

To iterate through the values see this question: Retrieving a property of a JSON object by index?

Trekco
  • 1,246
  • 6
  • 17