ChatGPT can provide answers to natural language or summarize given text. One of the benefits I have used as one who needs more time to develop simple code is to use ChatGPT to interpret my prompt and write code. I use Google Sheets quite often, and I use appscript to transfer and manipulate the data. As someone who used to be a software developer but no longer practices it, I don’t have the level of proficiency I used to have, nor the time to develop. I have used ChatGPT to manage my department’s projects and resources. It’s important to note that I did not share any company data to ChatGPT.

Before ChatGPT, it took me days of late-night coding to learn Apps Script and build code that works. Since using ChatGPT, the same code that took me many hours is now possible in seconds. Quite amazing!

The purpose of this blog is to illustrate ChatGPT’s coding functionality. I asked Bing AI to provide me with a list of public APIs I can use, and it listed this site (data.gov). I chose “Demographic Statistics By Zip Code – Demographic Statistics By Zip Code.”

Here is my prompt:

ChatGPT:

ChatGPT also provides some instruction.

To run this code, you will need to follow these steps:

  1. Open the Google Sheet where you want to insert the data.
  2. From the menu, select Tools -> Script editor. This will open the Google Apps Script editor in a new window.
  3. Paste the code into the editor.
  4. Save the script and give it a name.
  5. Run the script by clicking the Run button or by selecting Run -> insertJSONdata from the menu.

The script will fetch the JSON data from the specified URL, parse it, and insert it into the Data worksheet of the specified Google Sheet. The first row will contain the headers, and each subsequent row will contain the data. If there was any previous data on the sheet, it will be cleared before the new data is inserted.

I followed the instructions above and the screenshot below shows the successful execution of the code. I did not have to change the code provided!

No alt text provided for this image

Here is the result:

No alt text provided for this image

One more functionality of ChatGPT is that it provides test cases.

I prompted it with the following: Provide test cases for the code above.

Here is ChatGPT’s response:

To test the code, you can follow these steps:

  1. Open the Google Sheet where you want to insert the data.
  2. From the menu, select Tools -> Script editor. This will open the Google Apps Script editor in a new window.
  3. Paste the code into the editor.
  4. Save the script and give it a name.
  5. Run the script by clicking the Run button or by selecting Run -> insertJSONdata from the menu.

After running the script, you should see the data from the provided JSON source inserted into the Data worksheet of the specified Google Sheet.

Here are some test cases you can use to verify that the code is working correctly:

Test Case 1: Verify that headers are inserted correctly

  • Verify that the first row of the Data worksheet contains the headers of the JSON data source in the correct order.

Test Case 2: Verify that data is inserted correctly

  • Verify that the data from the JSON data source is inserted into the Data worksheet in the correct order.
  • Verify that the data types of the inserted data match the data types of the corresponding columns in the JSON data source.

Test Case 3: Verify that the worksheet is cleared before new data is inserted

  • Insert some data into the Data worksheet manually.
  • Run the script and verify that the previously inserted data is cleared before the new data from the JSON data source is inserted.

Test Case 4: Verify that the script runs without errors

  • Run the script and verify that it runs without throwing any errors.

This blog post is to illustrate one of ChatGPT’s functionality. It fits my use case as someone who needs simple scripts but does not have time nor the interest to spend hours to code. Other alternative AI tools exist for more sophisticated coding, like GitHub Copilot and other alternatives.

How have you used ChatGPT?