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

Add ability to import import JSON-P data #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions ImportJSON.gs
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,17 @@ function ImportJSONFromSheet(sheetName, query, options) {
**/
function ImportJSONAdvanced(url, fetchOptions, query, parseOptions, includeFunc, transformFunc) {
var jsondata = UrlFetchApp.fetch(url, fetchOptions);
var object = JSON.parse(jsondata.getContentText());

return parseJSONObject_(object, query, parseOptions, includeFunc, transformFunc);
try {
var object = JSON.parse(jsondata.getContentText());
return parseJSONObject_(object, query, parseOptions, includeFunc, transformFunc);
}
catch(err) {
var object = jsondata.getContentText();
var firstBr = object.indexOf("[") > object.indexOf("{") ? object.indexOf("{") : object.indexOf("[");
var lastBr = object.lastIndexOf(")");
var newObject= JSON.parse(object.substring(firstBr, lastBr));
return parseJSONObject_(newObject, query, parseOptions, includeFunc, transformFunc);
}
}

/**
Expand Down