Joe Consterdine Joe Consterdine - 1 year ago 82
Javascript Question

Get JSON Object property?

I'm trying to get the property information for 'Kind' in the JSON data here:

I'm currently just getting 18 'undefined' printed out to the console.

Where am I going wrong?


var jsonData = $.getJSON('');

for(var key in jsonData) {

Answer Source

$.getJSON returns a promise (more specifically, a jqXHR object which implements the promise interface), not the results of parsing the HTTP response as JSON.

Additionally, when you iterate over an object with in, the values you get will be the names of the properties as strings. These don't have kind properties.

To get to kind you need to read the value, not the property name.

It's best to avoid in for arrays though. forEach is usually a better approach.

function processResponse(parsed_data) {

function processItem(current_value) {

var jqXHR = $.getJSON('');

<script src=""></script>