{"id":553,"date":"2021-06-13T23:15:39","date_gmt":"2021-06-13T22:15:39","guid":{"rendered":"http:\/\/jimblackler.com\/blog\/?p=553"},"modified":"2021-06-13T23:15:39","modified_gmt":"2021-06-13T22:15:39","slug":"json-to-google-sheets-importer-written-in-javascript-and-java","status":"publish","type":"post","link":"https:\/\/jimblackler.com\/?p=553","title":{"rendered":"JSON to Google Sheets importer written in JavaScript and Java"},"content":{"rendered":"\n<p>I&#8217;ve written about how much I like <a href=\"https:\/\/en.wikipedia.org\/wiki\/JSON\" data-type=\"URL\" data-id=\"https:\/\/en.wikipedia.org\/wiki\/JSON\">JSON<\/a> before. It&#8217;s a really convenient way to store and transmit data across many different applications.<\/p>\n\n\n\n<p>I also like Google Sheets, but while you can import CSV data, it&#8217;s not easy to import JSON data. This is a shame because I use tools that output data in JSON that would be really convenient to view in Sheets.<\/p>\n\n\n\n<p>I didn&#8217;t like any of the workarounds I could find on the web, so I wrote my own. To make it as easy as possible for users, it uses the JavaScript Google Sheets API which means that the whole app can run in a website easily, and my App Engine site doesn&#8217;t have to deal with any user data (Authentication is done on the server because the client side authentication isn&#8217;t working well with browsers that prohibit third party cookies.) The application is already online, hosted on App Engine at <a href=\"https:\/\/jsonworkspace.appspot.com\/\">https:\/\/jsonworkspace.appspot.com\/<\/a><\/p>\n\n\n\n<p>The main requirement is that the data is formatted as a JSON array. Each element will be converted to a Google Sheets row, with the columns set from the dictionary keys found in object. For example, pasting the below code into the form..<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;\n  {\n    \"Title\": \"The Godfather\",\n    \"Year\": 1972,\n    \"Stars\": &#91;\"Marlon Brando\", \"Al Pacino\", \"James Caan\"]\n  },\n  {\n    \"Title\": \"Gone With the Wind\",\n    \"Year\": 1939,\n    \"Stars\": &#91;\"Clark Gable\", \"Vivien Leigh\"]\n  },\n    {\n    \"Title\": \"Jaws\",\n    \"Year\": 1975,\n    \"Stars\": &#91;\"Roy Scheider\", \"Robert Shaw\", \"Richard Dreyfuss\"]\n  }\n]<\/code><\/pre>\n\n\n\n<p>.. would result in the following Google Sheet being created for the user when the Import button was pressed.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"223\" src=\"https:\/\/jimblackler.com\/blog\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-13-at-23.06.24-1024x223.png\" alt=\"\" class=\"wp-image-555\" srcset=\"https:\/\/jimblackler.com\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-13-at-23.06.24-1024x223.png 1024w, https:\/\/jimblackler.com\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-13-at-23.06.24-300x65.png 300w, https:\/\/jimblackler.com\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-13-at-23.06.24-768x167.png 768w, https:\/\/jimblackler.com\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-13-at-23.06.24-500x109.png 500w, https:\/\/jimblackler.com\/wp-content\/uploads\/2021\/06\/Screenshot-2021-06-13-at-23.06.24.png 1076w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>You can see in the above example how an embedded array (&#8221;stars&#8217;) was converted into named sub-columns in a process I call flattening. A similar process is used on dictionaries. This means that a variety of JSON documents can be imported; the importer is always able to convert the data to a 2D collection of cells. The only limit is the Google Sheets limits on the number of rows and columns.<\/p>\n\n\n\n<p>I hope people find it useful. Feel free to contact me at <a href=\"mailto:jimblackler@gmail.com\">jimblackler@gmail.com<\/a> with any queries or comments.<\/p>\n\n\n\n<p>The source is offered under an Apache License 2.0 and is available at <a href=\"https:\/\/github.com\/jimblackler\/jsonworkspace\">https:\/\/github.com\/jimblackler\/jsonworkspace<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve written about how much I like JSON before. It&#8217;s a really convenient way to store and transmit data across many different applications. I also like Google Sheets, but while you can import CSV data, it&#8217;s not easy to import JSON data. This is a shame because I use tools that output data in JSON [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-553","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/jimblackler.com\/index.php?rest_route=\/wp\/v2\/posts\/553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jimblackler.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jimblackler.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jimblackler.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jimblackler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=553"}],"version-history":[{"count":2,"href":"https:\/\/jimblackler.com\/index.php?rest_route=\/wp\/v2\/posts\/553\/revisions"}],"predecessor-version":[{"id":556,"href":"https:\/\/jimblackler.com\/index.php?rest_route=\/wp\/v2\/posts\/553\/revisions\/556"}],"wp:attachment":[{"href":"https:\/\/jimblackler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jimblackler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jimblackler.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}