This is the gatsby-styled-blog-starter demo site. To download the code and get some instructions visit the Github repository . To be informed about updates follow @greglobinski

Return JSON with ContentService

Many APIs across the web serve content using JSON and now you can too

September 16, 2017

Javascript Object Notation is one of the most common formats for sending data over the internet.

If you are building any sort of application for the web it is hard to believe that you wouldn’t have come across JSON somewhere along the way.

You actually can use a deployed web app with Google Apps Script to serve JSON data to other services on the web. It is like a simple backend server without any of the hosting fees!

In the documentation they give this example:

function doGet(request) {
  var events = CalendarApp.getEvents(
    new Date(Number(request.parameters.start) * 1000),
    new Date(Number(request.parameters.end) * 1000));
  var result = {
    available: events.length == 0
  return ContentService.createTextOutput(JSON.stringify(result))

In my video I do a little more of a deep dive into how to use the ContentService to serve your data. If you run into CORS problems you can also use JSONP.

Want to learn more about this? Send me a message on twitter or leave a comment below!


jordan rhea I started as a teacher and taught myself to code with Python and JavaScript. Now I am passionate about sharing code and strategies to make teachers (and other G Suite users) as effective as possible with technology.

© jordan rhea 2018