Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import JSON data into Google Sheets

I am pulling data from a web service and it is formatted as JSON. I am writing a Google Apps Script for Google Sheets that will populate the data for me. My problem is, I can't seem to get it to parse out.

Doing:

var dataset = myJSONtext; Browser.msgbox(dataset.item[0].key);  

errors out, saying:

item[0] is not defined.

Is there some built in way I should be doing this?

like image 369
joejoeson Avatar asked Apr 17 '10 15:04

joejoeson


People also ask

How do I automatically import data into Google Sheets?

In a Google Sheet, select Add-ons from the main menu, then Supermetrics > Launch. Select a data source from the list of available sources and authorize it to share data with Supermetrics. Build a query using the options available and then click Get Data to Table.

How do I convert a JSON to a spreadsheet?

On the spreadsheet window, in Excel's ribbon at the top, click the “Data” tab. On the “Data” tab, from the “Get & Transform Data” section, select Get Data > From File > From JSON. You will see your computer's standard “Import” window. Here, open the folder where your JSON file is located.


1 Answers

JSON.parse

For those who are seeing this in 2011+, as pointed out by Henrique Abreu at the Google support forum, Utilities.jsonParse is/will be deprecated. As you can see from the thread, there's a bug with this function that it does not work when your keys are numbers, ie "1234".

As suggested, you should be using JSON.stringify/parse.

like image 149
Anh-Kiet Ngo Avatar answered Sep 29 '22 05:09

Anh-Kiet Ngo