Q: JSON get parent values to a dropdown I need to get the parent values of a JSON file to a Dropdown. Following is my JSON. 
[
{
    "AAA": {
        "task": {
            "taskname": "Promobox",
            "component": [["asd", "3"], ["asd", "3"]]
        },
        "task": {
            "taskname": "Newswire",
            "component": [["asd", "3"], ["asd", "3"]]
        },
    },

    "BBB": {
        "task": {
            "taskname": "Video",
            "component": [["asd", "3"], ["asd", "3"]]
        },
        "task": {
            "taskname": "Documents",
            "component": [["asd", "3"], ["asd", "3"]]
        },
    }
}
]

I was able to get the of parent element if there was a value (ex: "AAA": "text") but in this case there is no value to the parent item. Following is my full code. What I need is to get AAA,BBB in the dropdown. 
JS FIDDDLE

A: Iterate the array of object and use for..in to get the key 


var arr = [{
  "AAA": {
    "task": {
      "taskname": "Promobox",
      "component": [
        ["asd", "3"],
        ["asd", "3"]
      ]
    },
    "task": {
      "taskname": "Newswire",
      "component": [
        ["asd", "3"],
        ["asd", "3"]
      ]
    },
  },

  "BBB": {
    "task": {
      "taskname": "Video",
      "component": [
        ["asd", "3"],
        ["asd", "3"]
      ]
    },
    "task": {
      "taskname": "Documents",
      "component": [
        ["asd", "3"],
        ["asd", "3"]
      ]
    },
  }
}]

var getKeys = [];
arr.forEach(function(item) {
  for (var keys in item) {
    getKeys.push(keys)
  }

})

console.log(getKeys)



A: The array results has only one element results=[{}]. Hence you should index it as result[0] to get the inner object.
And in the code, you were assigning value to the value property of option. But AAA and BBB are actually indexes. They have values.
The working code is:


$(document).ready(function() {
  var $el = $("#dropDown");
  var results = [{
    "AAA": {
      "task": {
        "taskname": "Promobox",
        "component": [
          ["asd", "3"],
          ["asd", "3"],
          ["asd", "3"],
          ["asd", "3"]
        ]
      },
      "task": {
        "taskname": "Newswire",
        "component": [
          ["asd", "3"],
          ["asd", "3"],
          ["asd", "3"],
          ["asd", "3"]
        ]
      },
    },

    "BBB": {
      "task": {
        "taskname": "Video",
        "component": [
          ["asd", "3"],
          ["asd", "3"],
          ["asd", "3"],
          ["asd", "3"]
        ]
      },
      "task": {
        "taskname": "Documents",
        "component": [
          ["asd", "3"],
          ["asd", "3"],
          ["asd", "3"],
          ["asd", "3"]
        ]
      },
    }
  }];
  $el.empty(); // remove old options
  $el.append($("<option></option>")
    .attr("value", '').text('Please Select'));
  $.each(results[0], function(index, value) {//result[0]
    $el.append($("<option></option>")
      .attr("value", index).text(index));//index
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="dropDown">
</select>



A: Right now, you adding the whole object in your dropdown, You need to loop through your object to get the key. inside your function change the code to something like this : 
for (var key in value) {
   $el.append($("<option></option>")
         .attr("value", key).text(key));
}

https://jsfiddle.net/o5ju4kja/11/

A: How about using Object.keys?
var options = Object.keys(results[0]);

This will make options an array of "AAA","BBB".
Loop trough options and append an option element

A: If you just need the keys, you will first need to extract the object from the array, so you would do var object = result[0]. They you can simply do var keys = Object.keys(object), and you get an array of ['AAA', 'BBB', ...]
