VOOZH about

URL: https://thenewstack.io/how-to-convert-google-spreadsheet-to-json-formatted-text/

⇱ Convert a Google Spreadsheet to JSON-Formatted Text - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2025-03-06 09:02:14
Convert a Google Spreadsheet to JSON-Formatted Text
tutorial,
Data / JavaScript

Convert a Google Spreadsheet to JSON-Formatted Text

Make a bridge between JSON and Google Sheets.
Mar 6th, 2025 9:02am by Jack Wallen
👁 Featued image for: Convert a Google Spreadsheet to JSON-Formatted Text
(Editor’s note: This post, which has been updated, originally ran on May 6, 2022.)

Overview

This article provides a step-by-step guide on how to convert data from a Google Sheet into JSON-formatted text. The author explains the importance of JSON as a lightweight and easy-to-understand file format used for data interchange. They then walk through creating a Google Sheets document with sample data, freezing the title row, and adding an Apps Script to export the spreadsheet’s content as JSON.

The article includes:

  • An overview of JSON syntax rules
  • A brief explanation of why converting data to JSON is necessary
  • Step-by-step instructions on how to create a Google Sheet document, add an Apps Script, grant permissions, and export the spreadsheet data as JSON
  • The author provides examples throughout the guide, including creating a sample sheet with music album information and using the script to convert it into JSON format. They also discuss the potential limitations of this method.

Overall, this article is aimed at users who work with Google Sheets and need to convert their data into JSON format for use in development or configuration purposes.

JSON stands for JavaScript Object Notation and is an incredibly important open standard file/data interchange format that is lightweight and easy to understand. The JSON syntax rules are quite simple:

  • Data is key-value pairs.
  • Data is separated by commas.
  • Objects are placed within braces.
  • Arrays are stored within brackets.

JSON has numerous use cases and can be found in container manifests, configuration files, public/frontend/internal APIs, NoSQL databases, data exports, and much more. JSON has become so prevalent that it’s just about everywhere. Open a Linux app configuration and you’ll find JSON. Create a container manifest… there’s JSON!

Writing JSON isn’t all that challenging either. Take, for instance, this snippet of JSON code:

{"colors": [
   {"colorname" : "Black", "hex" : "000000"},
   {"colorname" : "White", "hex" : "FFFFFF"},
   {"colorname" : "Red", "hex" : "FF0000"}
]}

Pretty simple to understand. Each entry above is in the form of a key:value pair. You can write those all day, correct? But what if you already have a collection of data that you want to convert to JSON format. Say, for example, you have a Google Sheets document that is laid out in a format that can convert to JSON. Is it possible to then export that data into JSON-formatted text?

Why, yes, it is.

Let me show you.

The only thing you’ll need for this is a Google account.

Ready? Let’s get to work.

Creating Your Spreadsheet

I’m going to show a bit of fandom here, in that I’ve created a Google Sheets document for Rush albums. The data in the spreadsheet looks like this:

title band release label
Rush Rush 1974 Moon
Fly by Night Rush 1975 Mercury
Caress of Steel Rush 1975 Mercury
2112 Rush 1976 Mercury
A Farewell To Kings Rush 1977 Mercury
Hemispheres Rush 1978 Mercury
Permanent Waves Rush 1980 Mercury
Moving Pictures Rush 1981 Mercury
Signals Rush 1982 Mercury
Grace Under Pressure Rush 1984 Mercury
Power Windows Rush 1985 Mercury
Hold Your Fire Rush 1987 Mercury
Presto Rush 1989 Atlantic
Roll The Bones Rush 1991 Atlantic
Counterparts Rush 1993 Atlantic
Test For Echo Rush 1996 Atlantic
Vapor Trails Rush 2002 Atlantic
Snakes & Arrows Rush 2007 Atlantic
Clockwork Angels Rush 2012 Roadrunner

You can create a Sheets doc that contains any type of data. But once you’ve created your spreadsheet, it’s crucial that you freeze the title row. So after crafting your spreadsheet, select the top row and then click View > Freeze > 1 Row. If you don’t do this, the export will error out.

Okay, now that you’ve added your data into the spreadsheet, the next step is to create an Apps Script, a Google Cloud  JavaScript tool to integrate and automate tasks. To do this, click Extensions > Apps Script. In the resulting window, paste the following script found in this Gist.

After pasting the script, click Untitled Document and then name it something like JSON EXPORT. Next, click the Save button to save your work so far. Once it’s saved, click the Run button (Figure 1).

👁 Apps script

Figure 1: The run button is the small right-pointing arrow directly to the left of Debug.

When you click Run, you’ll be prompted that the script needs permissions to continue (Figure 2).

👁 Authorization popup.

Figure 2: Permissions are always an issue.

Make sure you walk through handing over the proper permissions for the account in question. Curing this process you’ll get a warning that Google hasn’t verified the app. Go ahead and okay that by clicking Advanced and then Go to JSON (unsafe). Finish up the permissions and you’ll be directed back to the Apps Script window.

If you now go back to the spreadsheet and reload it, you should see a new menu entry, labeled Export JSON (Figure 3).

👁 Google Sheets JSON tool.

Figure 3: Our new menu entry for the conversion to JSON.

Click Export JSON and then select Export JSON for this sheet. The script will do its thing and, when it completes, a pop-up will appear with your JSON-formatted text (Figure 4).

👁 Conversion to JSON.

Figure 4: Our Rush discography has been converted to a handy JSON format.

Copy and paste the output in the pop-up and use it wherever you need that JSON-formatted code.

One of the nice things about this script is that it allows you to keep adding to the spreadsheet. So you could build your data, export it to JSON, come back to the spreadsheet, add more data, and again export it to JSON and the new data will be included. Even better, you can close the spreadsheet, come back to it later, add more data, and export it as JSON (the Apps Script remains associated with the spreadsheet).

The one caveat is that when you re-open the spreadsheet, it might take a few seconds for the Export JSON menu to appear. If it doesn’t show up immediately, wait for it and it’ll pop into the toolbar.

Conclusion

If you work with Google Sheets to house data, and you need to (at some point) work that data into a JSON-formatted document, this is one of the best ways to do it. On top of which, this is just a cool way to demonstrate how developer-friendly Google apps can be. Give this script a whirl and see if you don’t start using it to create better JSON code for your development or configuration needs.

JSON Best Practices FAQ

Q: What is the primary purpose of using JSON?

A: The primary purpose of using JSON (JavaScript Object Notation) is to exchange data between systems, applications, or languages in a lightweight and easy-to-understand format.

Q: How do I write valid JSON code?

A: To write valid JSON code:

  • Use curly braces {} to define objects
  • Separate key-value pairs with commas
  • Use double quotes ” to enclose strings
  • Use square brackets [ ] to define arrays

Example:

Copy code

{

  “name”: “John Doe”,

  “age”: 30,

  “address”: {

“street”: “123 Main St”,

“city”: “Anytown”

  }

}

Q: What is the difference between single quotes and double quotes in JSON?

A: In JSON, both single quotes ” and double quotes “” can be used to enclose strings. However, it’s recommended to use double quotes consistently throughout your code.

Q: Can I use spaces or tabs in my JSON code?

A: Yes, you can use spaces or tabs in your JSON code for readability purposes. However, make sure to remove any unnecessary whitespace when using tools that parse JSON.

Q: How do I represent numbers and dates in JSON?

A: You can represent numbers as integers (42) or floating-point numbers (3.14). For dates, use the ISO 8601 format (e.g., 2022-07-25T14:30:00Z).

Example:

{

  “score”: 100,

  “date”: “2022-07-25”

}

Q: Can I nest objects in JSON?

A: Yes, you can nest objects within each other using the dot notation (e.g., object.property). This is useful for representing hierarchical data.

Example:

{

  “user”: {

“name”: “John Doe”,

“address”: {

   “street”: “123 Main St”,

   “city”: “Anytown”

}

  }

}

Q: How do I handle arrays in JSON?

A: You can represent arrays using square brackets [ ]. Each element within the array is separated by a comma.

Example:

{

  “colors”: [“red”, “green”, “blue”]

}

Q: Can I use comments in my JSON code?

A: No, you cannot include comments directly in your JSON code. However, some tools may support parsing and processing of comment-like data structures (e.g., /* */ comments) when used with certain encoding schemes.

Q: How do I validate or parse JSON data?

A: There are several libraries and tools available for validating and parsing JSON data, such as:

These tools can help ensure that your JSON data conforms to the expected format and structure.

(Editor’s note: This post, which has been updated, originally ran on May 6, 2022.)

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.