Import JSON data into Google Sheets
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.
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")
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.