Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

# 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"
#     }
#   ]
# }

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "kind" "calendar#event"
CkJsonObject_UpdateString $json "etag" "some_etag"
CkJsonObject_UpdateString $json "id" "string value"
CkJsonObject_UpdateString $json "status" "string value"
CkJsonObject_UpdateString $json "htmlLink" "string value"
CkJsonObject_UpdateString $json "created" "datetime value"
CkJsonObject_UpdateString $json "updated" "datetime value"
CkJsonObject_UpdateString $json "summary" "string value"
CkJsonObject_UpdateString $json "description" "string value"
CkJsonObject_UpdateString $json "location" "string value"
CkJsonObject_UpdateString $json "colorId" "string value"
CkJsonObject_UpdateString $json "creator.id" "string value"
CkJsonObject_UpdateString $json "creator.email" "string value"
CkJsonObject_UpdateString $json "creator.displayName" "string value"
CkJsonObject_UpdateBool $json "creator.self" 1
CkJsonObject_UpdateString $json "organizer.id" "string value"
CkJsonObject_UpdateString $json "organizer.email" "string value"
CkJsonObject_UpdateString $json "organizer.displayName" "string value"
CkJsonObject_UpdateBool $json "organizer.self" 1
CkJsonObject_UpdateString $json "start.date" "date value"
CkJsonObject_UpdateString $json "start.dateTime" "datetime value"
CkJsonObject_UpdateString $json "start.timeZone" "string value"
CkJsonObject_UpdateString $json "end.date" "date value"
CkJsonObject_UpdateString $json "end.dateTime" "datetime value"
CkJsonObject_UpdateString $json "end.timeZone" "string value"
CkJsonObject_UpdateBool $json "endTimeUnspecified" 1
CkJsonObject_UpdateString $json "recurrence[0]" "string value"
CkJsonObject_UpdateString $json "recurringEventId" "string value"
CkJsonObject_UpdateString $json "originalStartTime.date" "date value"
CkJsonObject_UpdateString $json "originalStartTime.dateTime" "datetime value"
CkJsonObject_UpdateString $json "originalStartTime.timeZone" "string value"
CkJsonObject_UpdateString $json "transparency" "string value"
CkJsonObject_UpdateString $json "visibility" "string value"
CkJsonObject_UpdateString $json "iCalUID" "string value"
CkJsonObject_UpdateNumber $json "sequence" "1234"

CkJsonObject_UpdateString $json "attendees[0].id" "string value"
CkJsonObject_UpdateString $json "attendees[0].email" "string value"
CkJsonObject_UpdateString $json "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..
CkJsonObject_put_I $json 0
CkJsonObject_UpdateBool $json "attendees[i].organizer" 1
CkJsonObject_UpdateBool $json "attendees[i].self" 1
CkJsonObject_UpdateBool $json "attendees[i].resource" 1
CkJsonObject_UpdateBool $json "attendees[i].optional" 1
CkJsonObject_UpdateString $json "attendees[i].responseStatus" "string value"
CkJsonObject_UpdateString $json "attendees[i].comment" "string value"
CkJsonObject_UpdateNumber $json "attendees[i].additionalGuests" "1234"

CkJsonObject_put_I $json 1
CkJsonObject_UpdateString $json "attendees[i].id" "string value"
CkJsonObject_UpdateString $json "attendees[i].email" "string value"
CkJsonObject_UpdateString $json "attendees[i].displayName" "string value"

CkJsonObject_UpdateBool $json "attendees[1].organizer" 1
CkJsonObject_UpdateBool $json "attendees[1].self" 1
CkJsonObject_UpdateBool $json "attendees[1].resource" 1
CkJsonObject_UpdateBool $json "attendees[1].optional" 1
CkJsonObject_UpdateString $json "attendees[1].responseStatus" "string value"
CkJsonObject_UpdateString $json "attendees[1].comment" "string value"
CkJsonObject_UpdateNumber $json "attendees[1].additionalGuests" "1234"

CkJsonObject_UpdateBool $json "attendeesOmitted" 1
CkJsonObject_UpdateString $json "extendedProperties.private.someKey" "string value"
CkJsonObject_UpdateString $json "extendedProperties.shared.someKey" "string value"
CkJsonObject_UpdateString $json "hangoutLink" "string value"
CkJsonObject_UpdateString $json "gadget.type" "string value"
CkJsonObject_UpdateString $json "gadget.title" "string value"
CkJsonObject_UpdateString $json "gadget.link" "string value"
CkJsonObject_UpdateString $json "gadget.iconLink" "string value"
CkJsonObject_UpdateNumber $json "gadget.width" "1234"
CkJsonObject_UpdateNumber $json "gadget.height" "1234"
CkJsonObject_UpdateString $json "gadget.display" "string value"
CkJsonObject_UpdateString $json "gadget.preferences.someKey" "string value"
CkJsonObject_UpdateBool $json "anyoneCanAddSelf" 1
CkJsonObject_UpdateBool $json "guestsCanInviteOthers" 1
CkJsonObject_UpdateBool $json "guestsCanModify" 1
CkJsonObject_UpdateBool $json "guestsCanSeeOtherGuests" 1
CkJsonObject_UpdateBool $json "privateCopy" 1
CkJsonObject_UpdateBool $json "locked" 1
CkJsonObject_UpdateBool $json "reminders.useDefault" 1
CkJsonObject_UpdateString $json "reminders.overrides[0].method" "string value"
CkJsonObject_UpdateNumber $json "reminders.overrides[0].minutes" "1234"
CkJsonObject_UpdateString $json "source.url" "string value"
CkJsonObject_UpdateString $json "source.title" "string value"
CkJsonObject_UpdateString $json "attachments[0].fileUrl" "string value"
CkJsonObject_UpdateString $json "attachments[0].title" "string value"
CkJsonObject_UpdateString $json "attachments[0].mimeType" "string value"
CkJsonObject_UpdateString $json "attachments[0].iconLink" "string value"
CkJsonObject_UpdateString $json "attachments[0].fileId" "string value"
CkJsonObject_UpdateString $json "attachments[1].fileUrl" "string value"
CkJsonObject_UpdateString $json "attachments[1].title" "string value"
CkJsonObject_UpdateString $json "attachments[1].mimeType" "string value"
CkJsonObject_UpdateString $json "attachments[1].iconLink" "string value"
CkJsonObject_UpdateString $json "attachments[1].fileId" "string value"

CkJsonObject_put_EmitCompact $json 0
puts [CkJsonObject_emit $json]

delete_CkJsonObject $json