1

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) tags

Mi Ro
  • 740
  • 1
  • 6
  • 31
  • Can you come witn an example of how you would like the output to be from the input you have in your example? – mathiasrw Jun 01 '16 at 12:35
  • I would like to check max # of tags and create respective columns and put one tag in one column..so if there is 10 records, one has 3 tags and rest 1, create 3 columns and for those with only one tag keep 2 empty – Mi Ro Jun 01 '16 at 12:59
  • ok, I've added screenshot from excel what is desired output..thx – Mi Ro Jun 01 '16 at 14:49

0 Answers0