Skip to content
Advertisement

Creating a JSON object from Google Sheets

I am trying to learn AppScript and I am using Google Sheets as an example. I want to create a simple JSON object using some data populated in the Sheet.

Table Example

Name    ID   Price   Qty
ABC     123  100      1
DEF     342   56      2
HIJ     233   90      3
IJK     213   68      5

I want the JSON out to be something like

JavaScript

I started by following this Youtube tutorial : https://www.youtube.com/watch?v=TQzPIVJf6-w. However that video talks about creating each column header as a the object. Where as i want the Column name to be the key and the Row value to be the value.

Here is my current AppScript Code

JavaScript

The output is a single object

JavaScript

PS: I am not a programmer, I am just learning some scripting in a hackey way. Apologies for not knowing the basics 🙂

Advertisement

Answer

Please try:

JavaScript

Test function:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement