I possess an array of weather data for various "stations," with most being situated at airports. This data has been gathered from web APIs and is currently presented as unordered arrays.
As an example:
Station: Chicago (O'Hare Airport) Temperature: 80 Wind Speed: 10 Description: Clear
Station: Portland International Airport Temperature: 71 Wind Speed: 10 Description: Cloudy
My intention is to convert this data into a JSON file. What would be the most efficient approach to accomplish this?
Eventually, I decided to tackle this challenge. I initialized an Object var stationsObjects = new Object();
I then went through all the weather stations and performed the following actions:
stationsObjects[station] = new Object();
stationsObjects[station].Temperature = value.Temperature;
stationsObjects[station].Wind Speed = value.Wind Speed;
stationsObjects[station].Pressure = value.Pressure;
stationsObjects[station].theTimeStamp = value.theTimeStamp;
stationsObjects[station].textDescription = value.textDescription;
Thus, I now have an object containing all the stations, essentially already structured in JSON format, correct?
{
"KBWI": {
"Temperature": 73,
"Wind Speed": 3,
"Pressure": 101560,
"theTimeStamp": "2018-05-11T12:54:00+00:00",
"textDescription": "Mostly Clear"
},
"KDCA": {
"Temperature": 74,
"Wind Speed": 3,
"Pressure": 101660,
"theTimeStamp": "2018-05-11T12:52:00+00:00",
"textDescription": "Partly Cloudy"
},
...
All that remains is to save this data to disk, correct? Is this the optimal method for achieving this goal?