How to build this JSON in javascript using this JSON Object

Viewed 42

I have this JSON, how do I iterate through this JSON Object in order to get a JSON like the one below this example?

{
    "Meta Data": {
        "1. Information": "Daily Prices (open, high, low, close) and Volumes",
        "2. Symbol": "AAPL",
        "3. Last Refreshed": "2020-06-17",
        "4. Output Size": "Compact",
        "5. Time Zone": "US/Eastern"
    },
    "Time Series (Daily)": {
        "2020-06-17": {
            "1. open": "355.1500",
            "2. high": "355.4000",
            "3. low": "351.0900",
            "4. close": "351.5900",
            "5. volume": "28429011"
        },
        "2020-06-16": {
            "1. open": "351.4600",
            "2. high": "353.2000",
            "3. low": "344.7200",
            "4. close": "352.0800",
            "5. volume": "41357182"
        },
        "2020-06-15": {
            "1. open": "333.2500",
            "2. high": "345.6800",
            "3. low": "332.5800",
            "4. close": "342.9900",
            "5. volume": "34702230"
        },

Desired JSON

{"close":69.06,"date":"20161020","high":70.1,"low":68.51,"open":68.87,"openInt":0,"volume":736533}

How do I append on each list the value

"openInt":0

and get the date of each element while appending it to the new desired JSON?

"2020-06-15":

Currently I'm able to build the JSON with this code

const timeSeries = json['Time Series (1min)'];
var data = [];
Object.keys(timeSeries).forEach(key => {
   const d = timeSeries[key];
   d.date = new Date(key);
   data.push( d );
});

And it returns a list of jsons like this

{"close":69.06,"high":70.1,"low":68.51,"open":68.87,"volume":736533}

I know that to get the format date I would use

var parseDate = d3.timeParse("%Y%m%d"); // 20150630
0 Answers
Related