json-grid icon indicating copy to clipboard operation
json-grid copied to clipboard

bug

Open wjllz opened this issue 2 years ago • 2 comments

hey, this seems can't convert this json rightly:

{"formed": [
	0,
	1,
	2,
	3,
	4,
	5,
	6
]}

wjllz avatar Oct 27 '22 12:10 wjllz

mini_patch, maybe buggy.... but it works... but I believe it should be buggy code....

  var rows = this.data.map(function (obj, index) {
    var tr = DOMHelper.createElement('tr')
    var firstTd = DOMHelper.createElement('td', typeof index);

    firstTd.appendChild(new JSONGrid(index).generateDOM());
    tr.appendChild(firstTd);
   
    // [+] add by 18f
    if(typeof obj != 'object'){
        var td = DOMHelper.createElement('td', typeof obj, 'table-wrapper');
        td.appendChild(new JSONGrid(obj).generateDOM());
        tr.appendChild(td);
    }
   // [+] end patch

    keys.forEach(function (key, keyIdx) {
      var td = DOMHelper.createElement('td', typeof obj, 'table-wrapper');
      var value = (obj[key] === undefined || obj[key] === null)
        ? '' + obj[key]
        : obj[key]
        ;
      td.appendChild(new JSONGrid(value).generateDOM());
      tr.appendChild(td);
    });

    return tr;
  });

wjllz avatar Oct 27 '22 14:10 wjllz

The patch code which I think is bug, it is because that:

I assume keys always be empty set when obj is not a object, but is it always true? If not, critical bug will happened :(

The original writer write this code:

When we call processArray, the element of the array always be a object, so it can't deal with [1, 2, 3, 4, 5]. in this way, keys will be empty set....

And I think there are another bug:

"date": ["111", "222", "333"],

use https://www.araujoigor.com/en/json-grid u will found the resolve result is wrong...

make my patch be this:

    // [+] add by 18f
    if(typeof obj != 'object'){
        var td = DOMHelper.createElement('td', typeof obj, 'table-wrapper');
        td.appendChild(new JSONGrid(obj).generateDOM());
        tr.appendChild(td);
        return tr;
    }
   // [+] end patch

get this result:

image

Still wrong... but now it is easy read....

wjllz avatar Oct 27 '22 14:10 wjllz