r/GoogleAppsScript • u/Comfortable-Wafer313 • May 11 '26
Question Loading bulk data from a JSON file
Hi everyone. I'm working on a sort of bulk data processing project for personal use/funsies. I have experience with programming/development, but haven't ever really used google scripts before.
A quick rundown of what I'm trying to do: There's a particular website that hosts their database's bulk data as a downloadable .json file, formatted as:
[
{attribute:"",attribute:"",attribute:""},
{attribute:"",attribute:"",attribute:""}
]
For example, though it's something to the tune of 30 thousand objects, each of which with tens of attributes.
In order to work with this data, the overall concept I'm doing right now is:
const url = "https://www.theurl.dom/file.json" //set url
const data = UrlFetchApp.fetch(url) //fetch data from url
var text = data.getContentText() //convert data
//I do the below to remove the encasing square brackets and respective newline characters at the beginning/end of the file and leave only the objects themselves
text = text.slice(2)
text = text.slice(0,-2)
var objarr = text.split('\n') //put each object into an array, delimited by newline
Logger.log(objarr[objarr.length - 1])
now it's working kinda sorta not really. Breaking the objects (as strings for now) into individual array items works fine in the strictest sense. The problem is, when I output to log as above, the last item in the array is object 11300-ish out of >30000 objects.
So I'm not super sure what limitation I'm running into. Also, from that data, I only really need 2 of the attributes per object to accomplish what I'm trying to do. But if I can't even load the entire database to trim them down, I'm not sure how to get there, yknow? Is there some other way I should be importing or processing the data for it to not truncate the number of objects? Or am I kinda screwed, because while I only need 2 of the attributes per object, I *do* need all of the objects
View all comments
Show parent comment
1
u/Comfortable-Wafer313 May 11 '26
So the follow up was pretty quick. Trying what you posted, I get error:
Unterminated string in JSON at position 52394848 (line 11354 column 5503)So I tried changing the argument for parse() a step earlier to pass in the fetched data before getting it as text. Same error. So (I could be wrong) but it seems like I'm running into a storage limit for the amount of data that fetch() is able to pull in? because it seems to truncate at the same point consistently whether I json.parse(text) json.parse(data) or try to manually parse the data.