Import JSON data into Google Sheets

50,307

Solution 1

Apps script is (pretty much) just Javascript; plain-old JSON.parse is your best option for parsing JSON into an object representation.

You can also use JSON.stringify to serialize an object into a string representation.

Solution 2

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.

Solution 3

A 2013 update -- Check out the ImportJSON library at

http://blog.fastfedora.com/projects/import-json

"ImportJSON imports data from public JSON APIs into Google Spreadsheets. It aims to operate similarly to how the native Google Spreadsheet functions ImportData and ImportXML work."

Code available here and he has submitted it to the Script Gallery: https://raw.github.com/fastfedora/google-docs/master/scripts/ImportJSON/Code.gs

Example usage: After putting the code in your Google spreadsheet's Script Editor, then paste this in cell A1 of the sheet:

=ImportJSON("http://gdata.youtube.com/feeds/api/standardfeeds/most_popular?v=2&alt=json", "/feed/entry/title,/feed/entry/content",               "noInherit,noTruncate,rawHeaders")

Solution 4

Use this gist : https://gist.github.com/varun-raj/5350595a730a62ca1954

Replace

http://example.com/feeds?type=json

with your JSON url

Add your entities here

rows.push([data.id, data.name,data.email]);
Share:
50,307
joejoeson
Author by

joejoeson

Updated on August 27, 2020

Comments

  • joejoeson
    joejoeson over 3 years

    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?