user1156596 user1156596 - 16 days ago 4
Javascript Question

How to pull properties and their values out of a JSON object

I have the following json object being returned and stored in a variable called data:

{"data":{"min":1,"q1":59,"median":117,"q3":175,"max":233}}


Since this is a single object and not an array of objects, I cannot do data[0], data[1] etc..

How can I pull out the min property and its value and store in a variable?

I've tried
var test = JSON.parse(data)
and then
array.push([test.min])
but have failed.

Is there an easier way to do this?

Answer

var obj = {
   "data": {
      "min": 1,
      "q1": 59,
      "median": 117,
      "q3": 175,
      "max": 233
   }
};
console.log(obj["data"]["min"]);