It's pretty common to convert spreadsheet values to an array of JSON objects using the header row as the property keys, and you'll find many examples of that around this site. It's a little less common, but equally useful, to convert Docs tables to JSON objects (and back). The object model of Docs is a little less friendly to structured data than that of sheets, but a simple trick can turn these less friendly elements into arrays. This article shows a couple of snippets for managing this as a very simple pattern.
Let's start with a document with this table in it, which I want to convert into an array of objects
The key to keeping this simple is to tranform the table and row objects into arrays which are more convenient to deal with.
using this small function
Here's the opposite - takes a an array of JSON objects and creates a table for them. Let's assume that the table already exists, so the first thing it needs to do is clear that table, then repopulate with the new data.
For more like this, see Google Apps Scripts snippets. Why not join our forum, follow the blog or follow me on twitter to ensure you get updates when they are available.
You want to learn Google Apps Script?
Learning Apps Script, (and transitioning from VBA) are covered comprehensively in my my book, Going Gas - from VBA to Apps script, available All formats are available now from O'Reilly,Amazon and all good bookshops. You can also read a preview on O'Reilly.
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > Going Gas >