0

I have a JSON file:

{  
   "request":{  
      "command":"series",
      "series_id":"PET.EMD_EPD2DXL0_PTE_NUS_DPG.W"
   },
   "series":[  
      {  
         "series_id":"PET.EMD_EPD2DXL0_PTE_NUS_DPG.W",
         "name":"U.S. No 2 Diesel Ultra Low Sulfur (0-15 ppm) Retail Prices, Weekly",
         "units":"Dollars per Gallon",
         "f":"W",
         "unitsshort":"$\/gal",
         "description":"U.S. No 2 Diesel Ultra Low Sulfur (0-15 ppm) Retail Prices",
         "copyright":"None",
         "source":"EIA, U.S. Energy Information Administration",
         "iso3166":"USA",
         "geography":"USA",
         "start":"20070205",
         "end":"20180319",
         "updated":"2018-03-19T17:20:45-0400",
         "data":[  
            [  
               "20180319",
               2.972
            ],
            [  
               "20070205",
               2.463
            ]
         ]
      }
   ]
}

How can I access the value: 2.972 in "data" using javascript or maybe even php?

Using javascript I tried to output it in console:

var globalJSON;
jQuery.getJSON('myfile.json', function(data) {

    globalJSON = data;
    dataReady();

});

function dataReady(){

console.log(globalJSON.series.data[0]);

}

I get the error "Cannot read property 'data' of undefined, and whatever I do it doesn't print anything after "globalJSON.series". Any help would be much appreciated, thank you!

iamx
  • 49
  • 1
  • 12

0 Answers0