I have a site that I'm working on using Django that makes API requests to get information about cars. These requests are triggered by JS events, which go to a created URL that connects to a view. In my view, I make the actual API request and use the .json()
method to get the returned JSON from the response.
What I'm having trouble doing however is getting a certain index/value from this response.
Here is an example of a response I would receive:
{
"equipment": [{
"id": "20047746549",
"name": "Specifications",
"equipmentType": "OTHER",
"availability": "STANDARD",
"attributes": [{
"name": "Aerodynamic Drag (cd)",
"value": "0.26"
}, {
"name": "Ege Highway Mpg",
"value": "29"
}, {
"name": "Epa Combined Mpg",
"value": "23"
}, {
"name": "Epa City Mpg",
"value": "20"
}, {
"name": "Curb Weight",
"value": "3957"
}, {
"name": "Turning Diameter",
"value": "39.0"
}, {
"name": "Manufacturer 0 60mph Acceleration Time (seconds)",
"value": "6.6"
}, {
"name": "Epa Highway Mpg",
"value": "29"
}, {
"name": "Tco Curb Weight",
"value": "3957"
}, {
"name": "Ege Combined Mpg",
"value": "23"
}, {
"name": "Fuel Capacity",
"value": "19.8"
}, {
"name": "Ege City Mpg",
"value": "20"
}]
}],
"equipmentCount": 1
}
What I'm trying to get is the "value": "3957"
that corresponds to the "name": "Curb Weight"
attribute
The way I thought about doing so (in Python) was jsonResponse['equipment'][0]['attributes'][4]['value']
however the index is not always the same for this Curb Weight attribute. Sometimes the index is 5, sometimes 6, etc.
Is there anyway to get this Curb Weight attribute, or any other attribute, by the value of it's "name"
key?