How would I go about accessing the following api with Javascript? https://www.fueleconomy.gov/feg/ws/ They state that "Data are available in either JSON or XML format." and I have no clue how to actually access it in JSON format.
I'm new to using APIs and my end goal is to be able to view the MPG of user searched vehicles.
I've used the following code to get a working XML response in the console:
console.log('starting')
request.open('GET', 'https://www.fueleconomy.gov/ws/rest/vehicle/emissions/31873', true)
request.onload = function () {
var parser, xmlDoc;
var data = this.response
parser = new DOMParser();
xmlDoc = parser.parseFromString(data,"text/xml");
console.log(xmlDoc)
}
request.send()