Nom Nom - 3 months ago 15
JSON Question

Parsing a JSON file - Subarray or inside square brackets node.js

I'm trying to parse a JSON API response using node.js. I have everything down but at one point (and this has to be simple), I'm completely stuck on how to approach the subarray or something.

Here's an example of what I want to accomplish. (Ignore the TF2 theme)

"AWPer Hand":
{
"defindex": [851],
"prices": {
"1": {
"Tradable": {
"Craftable": [{
"value": 15.33,
"currency": "metal",
"difference": -0.33,
"last_update": 1469842566,
"value_raw": 15.33
}]
}
},
"6": {
"Tradable": {
"Craftable": [{
"value": 3,
"currency": "metal",
"difference": 0.17,
"last_update": 1466442983,
"value_raw": 3
}]
}
},
"11": {
"Tradable": {
"Craftable": [{
"value": 5,
"currency": "keys",
"difference": -4.75,
"last_update": 1469371613,
"value_raw": 102.475
}]
}
}
}
}


It's not the proper format as there's a lot inside the file, though to get the format of how it looks mostly I have this line of code that works

var obj = JSON.parse(data);
var price = obj['response']['items'][itemName]['prices'][quality]['Tradable']['Craftable']


(The example response would be the [itemName] on wards)

Inside the craftable there's a subarray around square brackets, how would I parse this properly inside node.js to get the "value_raw" ID?

Thank you for your time!

Answer

i think the easiest way would be

price[0].value_raw

since its and array which contains an object