Querying JSON object using JSON select - javascript

I am working on this demo. Why am I not able to query the JSON object by using the jsonSelect plugin?
var jsonData = {
"name": {
"first": "Lloyd",
"last": "Hilaiel"
},
"favoriteColor": "yellow",
"languagesSpoken": [{
"language": "Bulgarian",
"level": 2
}, {
"language": "English",
"level": 1
}, {
"language": "Spanish",
"level": 7
}]
};
var selector = '.name > *';
JSONSelect.forEach(selector, jsonData, function (resultObj) {
$('body').append('<p>' + $.trim(JSON.stringify(resultObj, null, ' ')) + '</p>');
});

You cannot directly include the JS file from Github. You need to host it yourself or find a CDN.

Related

how to export complex json to excel with alasql

I have a json like this (there might be some syntax errors, I did extract and rewrite some private data)
"todo-items": [{
"id": 3511710,
"company-name": "company1",
"author" : "Jon Doe",
"tags": [{
"id": 10101,
"name": "2.Marketing Sales",
"color": "#f78234"
}],
"creation-date": 20160101
}, {
"id": 3511474,
"company-name": "company1",
"author" : "Jon Don",
"tags": [{
"id": 10101,
"name": "2.Marketing Sales",
"color": "#f78234"
}, {
"id": 10103,
"name": "4.Automotive",
"color": "#9b7cdb"
}],
"creation-date": 20160101
}, {
"id": 3511478,
"company-name": "company1",
"author" : "Peter Jon Doe",
"tags": [{
"id": 10101,
"name": "2.Marketing Sales",
"color": "#f78234"
}, {
"id": 9706,
"name": "3.sales",
"color": "#37ced0"
}, {
"id": 9562,
"name": "3.IT",
"color": "#37ced0"
}],
"creation-date": 20160101
}]
and I use alasql with xlsx.core libraries to export this to excel file.
For first I remove STATUS from original json (provided by teamwork API) and then I change JSON to javascript array
$.ajax({
type: "GET",
url: requrl,
headers: {"Authorization": "BASIC " + window.btoa(key + ":xxx")},
success: function(data) {
delete data.STATUS;
//alert(data);
//console.log(data);
var arr = $.map(data, function(el) { return el });
//console.log(arr);
alasql("SELECT * INTO XLSX('test.xlsx',{headers:true}) FROM ? ",[arr]);
},
error: function(response) {
alert(response);
}
});
this works nice and I can my json extract as excel file
but I have issues with tags objects in this json..when I change it to array and then save it in excel, all columns are ok except tags, where I see just [object][object]
Could you help me how to get these tags also into correct array? The best would be one tag = one column in excel
edit:
this is desired output - max # of tags in JSON will define number of columns tags (doesnt matter if it is tags tags tags or tags tags2 tags3)

How to interpret javascript within a json file

I'm working with the form builder Alpaca, and I would like to interpret a javascript function within a json datasource file, to select a certain file :
/data/options.json :
"nature":{
"type": "select",
"dataSource": "function(e) {...}"
},
This file is loaded here :
/test.html :
$("#div").alpaca({
"optionsSource": "/data/options.json",
etc...
Is this possible ?
Thanks.
You can use eval as said :
object = {"nature":{
"type": "select",
"dataSource": "function(e) {alert('ok')}"
}
}
var x = eval("("+object.nature.dataSource+")");
x()
Demo
You could make the function call first, then add the result to you JSON with data.nature.push();
See this answer : Add data to JSON in JS
script type="text/javascript">
var JSON = {"nature":{
"type": "select"
}};
JSON.dataSource.push(function());
$("#form1").alpaca(JSON);
</script>
As the Alpace datasources doc, http://www.alpacajs.org/docs/api/datasources.html you can use custom function in the datasource parameter :
$("#field5").alpaca({
"schema": {
"type": "string",
"title": "Pick an Action Hero"
},
"options": {
"type": "select",
"dataSource": function(callback) {
callback([{
"value": "rambo",
"text": "John Rambo"
}, {
"value": "norris",
"text": "Chuck Norris"
}, {
"value": "arnold",
"text": "Arnold Schwarzenegger"
}]);
}
}
});

Having trouble using data retrieved with json in javascript, cannot sort the array

I am trying to sort out the data I retrieved from an api with javascript.
Code :
function getResults() {
var url = $.getJSON("http://api.api.com&leagues=SOCENGPRE&lang=en&format=jsonp&callback=?", function(jsondata){;
for(var i = 0; i < jsondata.length; i++)
for(var id in jsondata[i]) {
console.log("ID - " + id);
console.log("TEAM - " + jsondata[i][id].home_team);
}
});
}
Example of data retrieved :
{
"SOCENGPRE": {
"league_name": "Barclays Premier League",
"league_phid": null,
"league_type": null,
"fixtures": [
{
"id": "64714",
"code": "SOCENGPRE",
"event_slug": "west_ham-tottenham-1401290",
"home_team": "West Ham",
"away_team": "Tottenham",
},
{
"id": "64711",
"code": "SOCENGPRE",
"event_slug": "manchester_u-sunderland-1401286",
"home_team": "Manchester U",
"away_team": "Sunderland"
}
But using my code I cannot seem to get the results I am wanting.
I want to print out every games ID and Home Team. Any insights on why is my code not working? Thank you very much in advance!
UPDATE: I have removed the extra semi-colon but it's still not printing the data for me.
UPDATE 2: Regarding the requests for the URL. When I call it in a browser I get this huge result
?({"SOCENGPRE":{"league_name":"Barclays Premier League","league_phid":null,"league_type":null,"fixtures":[{"id":"64714","code":"SOCENGPRE","event_slug":"west_ham-tottenham-1401290","start":"1399117500","home_team":"West Ham","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t523.png","home_team_short":"","away_team":"Tottenham","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t498.png","away_team_short":"","phid":null},{"id":"64711","code":"SOCENGPRE","event_slug":"manchester_u-sunderland-1401286","start":"1399125600","home_team":"Manchester U","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t20790.png","home_team_short":"Man U","away_team":"Sunderland","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t382.png","away_team_short":"","phid":null},{"id":"64712","code":"SOCENGPRE","event_slug":"stoke-fulham-1401288","start":"1399125600","home_team":"Stoke","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t389.png","home_team_short":"","away_team":"Fulham","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t379.png","away_team_short":"","phid":null},{"id":"64706","code":"SOCENGPRE","event_slug":"aston_villa-hull-1401282","start":"1399125600","home_team":"Aston Villa","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t380.png","home_team_short":"","away_team":"Hull","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t511.png","away_team_short":"Hull","phid":null},{"id":"64710","code":"SOCENGPRE","event_slug":"newcastle-cardiff-1401287","start":"1399125600","home_team":"Newcastle","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t385.png","home_team_short":"","away_team":"Cardiff","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t524.png","away_team_short":"","phid":null},{"id":"64713","code":"SOCENGPRE","event_slug":"swansea-southampton-1401289","start":"1399125600","home_team":"Swansea","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t384.png","home_team_short":"Swansea","away_team":"Southampton","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t8482.png","away_team_short":"","phid":null},{"id":"64709","code":"SOCENGPRE","event_slug":"everton-manchester_c-1401285","start":"1399134600","home_team":"Everton","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t499.png","home_team_short":"","away_team":"Manchester C","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t383.png","away_team_short":"Man C","phid":null},{"id":"64707","code":"SOCENGPRE","event_slug":"arsenal-west_bromwich-1401281","start":"1399206600","home_team":"Arsenal","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t30773.png","home_team_short":"","away_team":"West Bromwich","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t816.png","away_team_short":"West Brom","phid":null},{"id":"64705","code":"SOCENGPRE","event_slug":"chelsea-norwich-1401283","start":"1399215600","home_team":"Chelsea","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t497.png","home_team_short":"","away_team":"Norwich","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t1438.png","away_team_short":"","phid":null},{"id":"64708","code":"SOCENGPRE","event_slug":"crystal_palace-liverpool-1401284","start":"1399316400","home_team":"Crystal Palace","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t518.png","home_team_short":"C. Palace","away_team":"Liverpool","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t381.png","away_team_short":"","phid":null},{"id":"64679","code":"SOCENGPRE","event_slug":"manchester_u-hull-1401252","start":"1399401900","home_team":"Manchester U","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t20790.png","home_team_short":"Man U","away_team":"Hull","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t511.png","away_team_short":"Hull","phid":null},{"id":"64630","code":"SOCENGPRE","event_slug":"manchester_c-aston_villa-1401198","start":"1399488300","home_team":"Manchester C","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t383.png","home_team_short":"Man C","away_team":"Aston Villa","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t380.png","away_team_short":"","phid":null},{"id":"64621","code":"SOCENGPRE","event_slug":"sunderland-west_bromwich-1401189","start":"1399488300","home_team":"Sunderland","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t382.png","home_team_short":"","away_team":"West Bromwich","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t816.png","away_team_short":"West Brom","phid":null},{"id":"64719","code":"SOCENGPRE","event_slug":"manchester_c-west_ham-1401296","start":"1399816800","home_team":"Manchester C","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t383.png","home_team_short":"Man C","away_team":"West Ham","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t523.png","away_team_short":"","phid":null},{"id":"64717","code":"SOCENGPRE","event_slug":"liverpool-newcastle-1401295","start":"1399816800","home_team":"Liverpool","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t381.png","home_team_short":"","away_team":"Newcastle","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t385.png","away_team_short":"","phid":null},{"id":"64720","code":"SOCENGPRE","event_slug":"norwich-arsenal-1401297","start":"1399816800","home_team":"Norwich","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t1438.png","home_team_short":"","away_team":"Arsenal","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t30773.png","away_team_short":"","phid":null},{"id":"64715","code":"SOCENGPRE","event_slug":"fulham-crystal_palace-1401293","start":"1399816800","home_team":"Fulham","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t379.png","home_team_short":"","away_team":"Crystal Palace","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t518.png","away_team_short":"C. Palace","phid":null},{"id":"64722","code":"SOCENGPRE","event_slug":"sunderland-swansea-1401299","start":"1399816800","home_team":"Sunderland","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t382.png","home_team_short":"","away_team":"Swansea","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t384.png","away_team_short":"Swansea","phid":null},{"id":"64723","code":"SOCENGPRE","event_slug":"tottenham-aston_villa-1401300","start":"1399816800","home_team":"Tottenham","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t498.png","home_team_short":"","away_team":"Aston Villa","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t380.png","away_team_short":"","phid":null},{"id":"64724","code":"SOCENGPRE","event_slug":"west_bromwich-stoke-1401301","start":"1399816800","home_team":"West Bromwich","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t816.png","home_team_short":"West Brom","away_team":"Stoke","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t389.png","away_team_short":"","phid":null},{"id":"64718","code":"SOCENGPRE","event_slug":"hull-everton-1401294","start":"1399816800","home_team":"Hull","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t511.png","home_team_short":"Hull","away_team":"Everton","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t499.png","away_team_short":"","phid":null},{"id":"64721","code":"SOCENGPRE","event_slug":"southampton-manchester_u-1401298","start":"1399816800","home_team":"Southampton","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t8482.png","home_team_short":"","away_team":"Manchester U","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t20790.png","away_team_short":"Man U","phid":null},{"id":"64716","code":"SOCENGPRE","event_slug":"cardiff-chelsea-1401292","start":"1399816800","home_team":"Cardiff","home_team_phid":null,"home_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t524.png","home_team_short":"","away_team":"Chelsea","away_team_phid":null,"away_team_logo":"\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t497.png","away_team_short":"","phid":null}]}});
Link to pastebin for easier reading of the data
Change your getResults function to be called after the JSON has been parsed, like so:
var myDataVar;
$.ajax({
url: "URL to JSON file here",
dataType: "text", //If you get an error here, change the type to "text"
success: function (data) {
myDataVar = $.parseJSON(data);
getResults();
}
});
The above code will save the JSON file's parsed data into a single variable.
It will then call a function to get the results, being this function:
function getResults() {
var fixturesLength = myDataVar.SOCENGPRE.fixtures.length - 1;
for (var i = 0; i <= fixturesLength; i++) {
console.log(myDataVar.SOCENGPRE.fixtures[i].id);
}
}
The above loop will print to the console every one of your fixtures ID's.
Test data used:
{
"SOCENGPRE": {
"league_name": "Barclays Premier League",
"league_phid": null,
"league_type": null,
"fixtures": [{
"id": "64714",
"code": "SOCENGPRE",
"event_slug": "west_ham-tottenham-1401290",
"start": "1399117500",
"home_team": "West Ham",
"home_team_phid": null,
"home_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t523.png",
"home_team_short": "",
"away_team": "Tottenham",
"away_team_phid": null,
"away_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t498.png",
"away_team_short": "",
"phid": null
}, {
"id": "64711",
"code": "SOCENGPRE",
"event_slug": "manchester_u-sunderland-1401286",
"start": "1399125600",
"home_team": "Manchester U",
"home_team_phid": null,
"home_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t20790.png",
"home_team_short": "Man U",
"away_team": "Sunderland",
"away_team_phid": null,
"away_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t382.png",
"away_team_short": "",
"phid": null
}, {
"id": "64712",
"code": "SOCENGPRE",
"event_slug": "stoke-fulham-1401288",
"start": "1399125600",
"home_team": "Stoke",
"home_team_phid": null,
"home_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t389.png",
"home_team_short": "",
"away_team": "Fulham",
"away_team_phid": null,
"away_team_logo": "\/\/dxnxhx88pdxyv.cloudfront.net\/logo\/32\/t379.png",
"away_team_short": "",
"phid": null
}]
}
}
Console results:
64714
64711
64712

How to split JSON into 2 arrays and before I pass it to getJSON for later manipulation?

I have a json data and i am trying to split it into 2 sets of data arrays One json data will hold all the values from "Construct" data values and the 2nd json data will hold the rest of the array and values for product,system etc etc.
I want to split it into 2 arrays before i pass it into getJSON . Once I split them into 2 then pass the restofJSONdata into getJSON vice versa
How can I split them into 2 arrays before i pass it to getJSON?
MY current code
<script type="text/javascript">
$(document).ready(function () // don't do anything until the document is loaded.
{
var baseUrl = "config.json";
console.log(baseUrl.html.splice(3)); // remove and log the empty fieldset
var constructgrp = baseUrl.html.shift(); // remove the first item (caption: "Construct")
var restofJSONdata = baseUrl.html;
alert(constructgrp);
$.getJSON(restofJSONdata, function (data) // call getJSON providing the complete url with search term and a JSONP callback
{
// console.log(data.html.splice(2,3));
// console.log("data " +data);
/*
console.log(data.html.splice(3,0)); // remove and log the empty fieldset
var constructgrp = data.html.shift(); // remove the first item (caption: "Construct")
var restofJSONdata = data.html;
alert(constructgrp); :*/
$("#demo-3-form").empty(); // clear out any previous results.
if (data.html.length < 1) $('#demo-3-forms').html("No results. Nada. Nuttin. Zippo.");
//$("#demo-3-form").empty(); // clear out any previous results.
// if (data.html.length < 1) $('#demo-3-forms').html("No results. Nada. Nuttin. Zippo.");
// $.each(this.constructgrp, function () // iterate over the results, constructing the HTML for the display.
// {
/*
var html =constructgrp.type +' :';
html += '<b>'+constructgrp.caption +'</b><br>';
html += ' <br>';
$.each(constructgrp.html, function() {
// alert(this.name);
html +='Title :' +this.title +'<br>';
html +='Name :' +this.name +'<br>';
html +='Value :' +this.value +'<br> ';
html +='Caption :' +this.caption +'<br><br> ';
// html += this.type +'<br><br> ';
});
$('#demo-3-form').hide().append(html).fadeIn(800); // fade in the results over 2 seconds.
*/
// });
$.each(restofJSONdata, function () // iterate over the results, constructing the HTML for the display.
{
var html =this.type +' :';
html += '<b>'+this.caption +'</b><br>';
html += ' <br>';
$.each(this.html, function() {
// alert(this.name);
html +='Title :' +this.title +'<br>';
html +='Name :' +this.name +'<br>';
html +='Value :' +this.value +'<br> ';
html +='Caption :' +this.caption +'<br><br> ';
// html += this.type +'<br><br> ';
});
$('#demo-3-form').hide().append(html).fadeIn(800); // fade in the results over 2 seconds.
});
});
//});
});
</script>
JSON code
config.json
{
"html": [{
"type": "fieldset",
"caption": "Construct",
"html": [{
"title": "tooltip data for rk",
"name": "rk_",
"value": "24",
"caption": "DNS Servers (a list of IP addresses separated by comas)",
"type": "textarea"
}, {
"title": "tooltip data for rk_ntpservers",
"name": "rk_ntpservers",
"value": "111.11.11.11",
"caption": " separated by comas",
"type": "textarea"
}, {
"title": "tooltip data for ff_eth0_ff",
"name": "ff_eth0_ff",
"value": "18",
"caption": "Public Address (0.0.0.0 to disable)",
"type": "text"
}, {
"title": "tooltip data for ff_eth0_netmask",
"name": "ff_eth0_netmask",
"value": "2.2.2.0",
"caption": "Public rk Netmask",
"type": "text"
}, {
"title": "tooltip data for ff_eth1_ff",
"name": "ff_eth1_ff",
"value": "0.0.0.0",
"caption": "MG Device rk (0.0.0.0 to disable)",
"type": "text"
}, {
"title": "tooltip data for ff_eth1_netmask",
"name": "ff_eth1_netmask",
"value": "2.2.2.0",
"caption": "MG Device rk Netmask",
"type": "text"
}, {
"title": "tooltip data for ff",
"name": "ff_gateway",
"value": "1",
"caption": "Gateway",
"type": "text"
}]
}, {
"type": "fieldset",
"caption": "Product",
"html": [{
"title": "tooltip data for product_ident",
"name": "product_ident",
"value": "78",
"caption": "Product Name",
"type": "text",
"disabled": "disabled"
}, {
"title": "tooltip data for product_svnversion",
"name": "product_svnversion",
"value": "7916",
"caption": "Revision",
"type": "text",
"disabled": "disabled"
}]
}, {
"type": "fieldset",
"caption": "System ",
"html": [{
"title": "tooltip data for system_license",
"name": "system_license",
"value": "HH",
"caption": "License",
"type": "text"
}, {
"title": "tooltip data for system_variant",
"name": "system_variant",
"value": "normal",
"caption": "Variant",
"type": "text"
}]
}, {
"type": "fieldset",
"class": "btn-fieldset",
"caption": "",
"html": [{
"type": "submit",
"id": "submitbtn",
"class": "btn btn-primary",
"value": "Save"
}]
}]
}
To split them into 2 arrays before pass it to getJSON you need to:
Get JSON
Split data into two pieces
var construct;
$.getJSON('PATH_TO_config.json', function(data) {
// splice will return first array and leaves rest in original data
construct = data.html.splice(0, 1);
// in the first parameter you have data.html[0] in the second
// data.html[1..3] from the original JSON
doSomethingWithData(construct, data.html);
}

Simple json reading the api

I have a query that produces the following results:
{
"data": [
{
"id": "1107702400"
},
{
"id": "1149862205",
"likes": {
"data": [
{
"name": "Penelope Test",
"category": "Arts/entertainment/nightlife",
"id": "411133928921438",
"created_time": "2012-05-23T11:41:27+0000"
},
The first id I can access through:
response.data[i].id
How do I retrieve the second id? (the one that goes data-id-data-id ?)
I have this function:
for(i=0;i<response.data.length;i++)
{
testdiv.innerHTML += response.data.data[i].id + '<br/>' ;
}
Which lets me print the first id.
What do I need to do in order to print the second id?
In your example data
response.data[i].likes.data[0].id

Categories