bradjasper / ImportJSON

Import JSON into Google Sheets, this library adds various ImportJSON functions to your spreadsheet
GNU Lesser General Public License v3.0
2.1k stars 1.06k forks source link

Logical true isn't recognized #143

Open GregE-369 opened 4 years ago

GregE-369 commented 4 years ago

values of true are output as text values while values of false are output as boolean values.

example file: https://data.ncaa.com/casablanca/scoreboard/football/fbs/2019/14/scoreboard.json

best regards, GregE

ttrentham commented 4 years ago

There definitely seems to be an issue with booleans. My experience is that values of true show up but false doesn't. However, I tried your sample and seemed to get mixed results. Still never saw a "false" value make it into the sheet.

krijnsent commented 4 years ago

The issue seems to be in the defaultTransform_ function. In there, there is a block where values are automatically transformed into a string and cut to max 256 characters. To prevent this from happening, you can add the noTruncate option and/or modify that bit of code:

=importjson("https://data.ncaa.com/casablanca/scoreboard/football/fbs/2019/14/scoreboard.json";;"noTruncate")

Or replace:

if (!hasOption_(options, "noTruncate") && data[row][column]) {
      data[row][column] = data[row][column].toString().substr(0, 256);
  }

By:

if (!hasOption_(options, "noTruncate") && data[row][column]) {
    if ((typeof data[row][column]) === 'number' || (typeof data[row][column]) === 'boolean') {
      data[row][column] = data[row][column];
    } else {
      data[row][column] = data[row][column].toString().substr(0, 256);
    }
  }
milosmns commented 3 years ago

@krijnsent is correct 👍

This should be the default behavior in here.