Search code examples
javascriptjsongoogle-apps-scriptgoogle-sheetscustom-function

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?


Solution

  • 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.