Sample code for 30+ languages & platforms
Xbase++

Google Calendar -- Generate Event JSON

See more Google Calendar Examples

Demonstrates how to generate the JSON for an event resource. This code can be used as a template for generating JSON to insert new events.

See https://developers.google.com/google-apps/calendar/v3/reference/events#resource for details about the Calender Event Resource JSON.

Chilkat Xbase++ Downloads

Xbase++
LOCAL oJson

//  This example (below) generates the following JSON:
//  Note: Your application code would construct the event JSON using your
//  desired subset of members.  For boolean values, you would pass 1 or 0.
//  For date or date/time values, you would pass the appropriately formatted date/time string.

//  {
//    "kind": "calendar#event",
//    "etag": "some_etag",
//    "id": "string value",
//    "status": "string value",
//    "htmlLink": "string value",
//    "created": "datetime value",
//    "updated": "datetime value",
//    "summary": "string value",
//    "description": "string value",
//    "location": "string value",
//    "colorId": "string value",
//    "creator": {
//      "id": "string value",
//      "email": "string value",
//      "displayName": "string value",
//      "self": true
//    },
//    "organizer": {
//      "id": "string value",
//      "email": "string value",
//      "displayName": "string value",
//      "self": true
//    },
//    "start": {
//      "date": "date value",
//      "dateTime": "datetime value",
//      "timeZone": "string value"
//    },
//    "end": {
//      "date": "date value",
//      "dateTime": "datetime value",
//      "timeZone": "string value"
//    },
//    "endTimeUnspecified": true,
//    "recurrence": [
//      "string value"
//    ],
//    "recurringEventId": "string value",
//    "originalStartTime": {
//      "date": "date value",
//      "dateTime": "datetime value",
//      "timeZone": "string value"
//    },
//    "transparency": "string value",
//    "visibility": "string value",
//    "iCalUID": "string value",
//    "sequence": 1234,
//    "attendees": [
//      {
//        "id": "string value",
//        "email": "string value",
//        "displayName": "string value",
//        "organizer": true,
//        "self": true,
//        "resource": true,
//        "optional": true,
//        "responseStatus": "string value",
//        "comment": "string value",
//        "additionalGuests": 1234
//      },
//      {
//        "id": "string value",
//        "email": "string value",
//        "displayName": "string value",
//        "organizer": true,
//        "self": true,
//        "resource": true,
//        "optional": true,
//        "responseStatus": "string value",
//        "comment": "string value",
//        "additionalGuests": 1234
//      }
//    ],
//    "attendeesOmitted": true,
//    "extendedProperties": {
//      "private": {
//        "someKey": "string value"
//      },
//      "shared": {
//        "someKey": "string value"
//      }
//    },
//    "hangoutLink": "string value",
//    "gadget": {
//      "type": "string value",
//      "title": "string value",
//      "link": "string value",
//      "iconLink": "string value",
//      "width": 1234,
//      "height": 1234,
//      "display": "string value",
//      "preferences": {
//        "someKey": "string value"
//      }
//    },
//    "anyoneCanAddSelf": true,
//    "guestsCanInviteOthers": true,
//    "guestsCanModify": true,
//    "guestsCanSeeOtherGuests": true,
//    "privateCopy": true,
//    "locked": true,
//    "reminders": {
//      "useDefault": true,
//      "overrides": [
//        {
//          "method": "string value",
//          "minutes": 1234
//        }
//      ]
//    },
//    "source": {
//      "url": "string value",
//      "title": "string value"
//    },
//    "attachments": [
//      {
//        "fileUrl": "string value",
//        "title": "string value",
//        "mimeType": "string value",
//        "iconLink": "string value",
//        "fileId": "string value"
//      },
//      {
//        "fileUrl": "string value",
//        "title": "string value",
//        "mimeType": "string value",
//        "iconLink": "string value",
//        "fileId": "string value"
//      }
//    ]
//  }

oJson := CreateObject("Chilkat.JsonObject")
oJson:UpdateString("kind", "calendar#event")
oJson:UpdateString("etag", "some_etag")
oJson:UpdateString("id", "string value")
oJson:UpdateString("status", "string value")
oJson:UpdateString("htmlLink", "string value")
oJson:UpdateString("created", "datetime value")
oJson:UpdateString("updated", "datetime value")
oJson:UpdateString("summary", "string value")
oJson:UpdateString("description", "string value")
oJson:UpdateString("location", "string value")
oJson:UpdateString("colorId", "string value")
oJson:UpdateString("creator.id", "string value")
oJson:UpdateString("creator.email", "string value")
oJson:UpdateString("creator.displayName", "string value")
oJson:UpdateBool("creator.self", 1)
oJson:UpdateString("organizer.id", "string value")
oJson:UpdateString("organizer.email", "string value")
oJson:UpdateString("organizer.displayName", "string value")
oJson:UpdateBool("organizer.self", 1)
oJson:UpdateString("start.date", "date value")
oJson:UpdateString("start.dateTime", "datetime value")
oJson:UpdateString("start.timeZone", "string value")
oJson:UpdateString("end.date", "date value")
oJson:UpdateString("end.dateTime", "datetime value")
oJson:UpdateString("end.timeZone", "string value")
oJson:UpdateBool("endTimeUnspecified", 1)
oJson:UpdateString("recurrence[0]", "string value")
oJson:UpdateString("recurringEventId", "string value")
oJson:UpdateString("originalStartTime.date", "date value")
oJson:UpdateString("originalStartTime.dateTime", "datetime value")
oJson:UpdateString("originalStartTime.timeZone", "string value")
oJson:UpdateString("transparency", "string value")
oJson:UpdateString("visibility", "string value")
oJson:UpdateString("iCalUID", "string value")
oJson:UpdateNumber("sequence", "1234")

oJson:UpdateString("attendees[0].id", "string value")
oJson:UpdateString("attendees[0].email", "string value")
oJson:UpdateString("attendees[0].displayName", "string value")

//  Note: We could alternately specify an index using "i", which allows
//  for an application to construct using a loop with a variable..
oJson:I := 0
oJson:UpdateBool("attendees[i].organizer", 1)
oJson:UpdateBool("attendees[i].self", 1)
oJson:UpdateBool("attendees[i].resource", 1)
oJson:UpdateBool("attendees[i].optional", 1)
oJson:UpdateString("attendees[i].responseStatus", "string value")
oJson:UpdateString("attendees[i].comment", "string value")
oJson:UpdateNumber("attendees[i].additionalGuests", "1234")

oJson:I := 1
oJson:UpdateString("attendees[i].id", "string value")
oJson:UpdateString("attendees[i].email", "string value")
oJson:UpdateString("attendees[i].displayName", "string value")

oJson:UpdateBool("attendees[1].organizer", 1)
oJson:UpdateBool("attendees[1].self", 1)
oJson:UpdateBool("attendees[1].resource", 1)
oJson:UpdateBool("attendees[1].optional", 1)
oJson:UpdateString("attendees[1].responseStatus", "string value")
oJson:UpdateString("attendees[1].comment", "string value")
oJson:UpdateNumber("attendees[1].additionalGuests", "1234")

oJson:UpdateBool("attendeesOmitted", 1)
oJson:UpdateString("extendedProperties.private.someKey", "string value")
oJson:UpdateString("extendedProperties.shared.someKey", "string value")
oJson:UpdateString("hangoutLink", "string value")
oJson:UpdateString("gadget.type", "string value")
oJson:UpdateString("gadget.title", "string value")
oJson:UpdateString("gadget.link", "string value")
oJson:UpdateString("gadget.iconLink", "string value")
oJson:UpdateNumber("gadget.width", "1234")
oJson:UpdateNumber("gadget.height", "1234")
oJson:UpdateString("gadget.display", "string value")
oJson:UpdateString("gadget.preferences.someKey", "string value")
oJson:UpdateBool("anyoneCanAddSelf", 1)
oJson:UpdateBool("guestsCanInviteOthers", 1)
oJson:UpdateBool("guestsCanModify", 1)
oJson:UpdateBool("guestsCanSeeOtherGuests", 1)
oJson:UpdateBool("privateCopy", 1)
oJson:UpdateBool("locked", 1)
oJson:UpdateBool("reminders.useDefault", 1)
oJson:UpdateString("reminders.overrides[0].method", "string value")
oJson:UpdateNumber("reminders.overrides[0].minutes", "1234")
oJson:UpdateString("source.url", "string value")
oJson:UpdateString("source.title", "string value")
oJson:UpdateString("attachments[0].fileUrl", "string value")
oJson:UpdateString("attachments[0].title", "string value")
oJson:UpdateString("attachments[0].mimeType", "string value")
oJson:UpdateString("attachments[0].iconLink", "string value")
oJson:UpdateString("attachments[0].fileId", "string value")
oJson:UpdateString("attachments[1].fileUrl", "string value")
oJson:UpdateString("attachments[1].title", "string value")
oJson:UpdateString("attachments[1].mimeType", "string value")
oJson:UpdateString("attachments[1].iconLink", "string value")
oJson:UpdateString("attachments[1].fileId", "string value")

oJson:EmitCompact := 0
? oJson:Emit()

oJson:destroy()