Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Support 1D- and 2D-arrays as input for URLs to allow usage inside ARRAYFORMULA #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

roman-orekhov
Copy link

This works now
=arrayformula(IMPORTJSON("https://www.binance.com/api/v3/ticker/price?symbol="&A2:B4&"", "/symbol,/price",))

@Kncuk
Copy link

Kncuk commented Jan 10, 2022

Hi, I believe this version also has the bottom row duplication problem, which I think was not the case for 1.5.0 (using that in one of my sheet and not duplication, tried 1.7.0 and it's there), wondering if it's possible for a fix?

@roman-orekhov
Copy link
Author

Hi, please provide example spreadsheet with the problem since I haven't seen any row duplication yet

@Kncuk
Copy link

Kncuk commented Jan 12, 2022

Hi, here is an issue regarding this problem

Here is an example sheet I have made.
Notice how everyone has only two rows (as they have two sets), but the very last one has a duplicate row at the end (3 instead of 2 like every others) (more specifically, check the row with videoid "po72SQKzLXk", notice how there are two identical rows, while all others have unique videoid as none of them are repeated

@roman-orekhov
Copy link
Author

This wasn't originally supported, I believe. The reason for "duplicate" is that you are trying to import whole JSON as a table when it's not a table, but contains a table (in "list" key) and there are other fields after the key with the table. Because of that the last row is first output as is and next time it is appended with the additional keys ("cursor" and "hasnext").

To get the table w/o non-table columns, pass the query as second parameter:
=ImportJSON(<your link here>, "/list")

@Kncuk
Copy link

Kncuk commented Jan 13, 2022

yeah I chose that as an example since it's formatted that way. The interesting thing is when using 1.5.0, it loads just fine in my another private sheet, and it seems to be the case for other users too (in the issue linked). Using /list has it working just fine too.

In any case, I also found this, which does seem to solve the duplication problem among some others, but has no support for array input yet.

@yodog
Copy link

yodog commented Jun 24, 2022

i accomplished something similar with

/**
 * Read list of URLs from range
 * Ex1: ImportJSON_RASG("sheet9!C2:C7")
 * Ex2: ImportJSON_RASG("myNamedRange")
 */

function ImportJSON_RASG(cellRange, query, parseOptions) {
  var arr = [];
  SpreadsheetApp.getActiveSheet().getRange(1,1).activate();
  const arrURL = SpreadsheetApp.getActiveSheet().getRange(cellRange).getValues().join().split(',');
  for (var url of arrURL) {
    try { arr.push(ImportJSON(url, query, parseOptions)); } 
    catch { SpreadsheetApp.getActiveSpreadsheet().toast(url, 'Error fetching data', 3); }
  }
  return arr.flat();
}

but your solution looks much better.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants