Sample code for 30+ languages & platforms
Zig

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

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // 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 true or false.
    // 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"
    //     }
    //   ]
    // }

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.updateString("kind", "calendar#event") catch {};
    json.updateString("etag", "some_etag") catch {};
    json.updateString("id", "string value") catch {};
    json.updateString("status", "string value") catch {};
    json.updateString("htmlLink", "string value") catch {};
    json.updateString("created", "datetime value") catch {};
    json.updateString("updated", "datetime value") catch {};
    json.updateString("summary", "string value") catch {};
    json.updateString("description", "string value") catch {};
    json.updateString("location", "string value") catch {};
    json.updateString("colorId", "string value") catch {};
    json.updateString("creator.id", "string value") catch {};
    json.updateString("creator.email", "string value") catch {};
    json.updateString("creator.displayName", "string value") catch {};
    json.updateBool("creator.self", true) catch {};
    json.updateString("organizer.id", "string value") catch {};
    json.updateString("organizer.email", "string value") catch {};
    json.updateString("organizer.displayName", "string value") catch {};
    json.updateBool("organizer.self", true) catch {};
    json.updateString("start.date", "date value") catch {};
    json.updateString("start.dateTime", "datetime value") catch {};
    json.updateString("start.timeZone", "string value") catch {};
    json.updateString("end.date", "date value") catch {};
    json.updateString("end.dateTime", "datetime value") catch {};
    json.updateString("end.timeZone", "string value") catch {};
    json.updateBool("endTimeUnspecified", true) catch {};
    json.updateString("recurrence[0]", "string value") catch {};
    json.updateString("recurringEventId", "string value") catch {};
    json.updateString("originalStartTime.date", "date value") catch {};
    json.updateString("originalStartTime.dateTime", "datetime value") catch {};
    json.updateString("originalStartTime.timeZone", "string value") catch {};
    json.updateString("transparency", "string value") catch {};
    json.updateString("visibility", "string value") catch {};
    json.updateString("iCalUID", "string value") catch {};
    json.updateNumber("sequence", "1234") catch {};

    json.updateString("attendees[0].id", "string value") catch {};
    json.updateString("attendees[0].email", "string value") catch {};
    json.updateString("attendees[0].displayName", "string value") catch {};

    // Note: We could alternately specify an index using "i", which allows
    // for an application to construct using a loop with a variable..
    json.setI(0);
    json.updateBool("attendees[i].organizer", true) catch {};
    json.updateBool("attendees[i].self", true) catch {};
    json.updateBool("attendees[i].resource", true) catch {};
    json.updateBool("attendees[i].optional", true) catch {};
    json.updateString("attendees[i].responseStatus", "string value") catch {};
    json.updateString("attendees[i].comment", "string value") catch {};
    json.updateNumber("attendees[i].additionalGuests", "1234") catch {};

    json.setI(1);
    json.updateString("attendees[i].id", "string value") catch {};
    json.updateString("attendees[i].email", "string value") catch {};
    json.updateString("attendees[i].displayName", "string value") catch {};

    json.updateBool("attendees[1].organizer", true) catch {};
    json.updateBool("attendees[1].self", true) catch {};
    json.updateBool("attendees[1].resource", true) catch {};
    json.updateBool("attendees[1].optional", true) catch {};
    json.updateString("attendees[1].responseStatus", "string value") catch {};
    json.updateString("attendees[1].comment", "string value") catch {};
    json.updateNumber("attendees[1].additionalGuests", "1234") catch {};

    json.updateBool("attendeesOmitted", true) catch {};
    json.updateString("extendedProperties.private.someKey", "string value") catch {};
    json.updateString("extendedProperties.shared.someKey", "string value") catch {};
    json.updateString("hangoutLink", "string value") catch {};
    json.updateString("gadget.type", "string value") catch {};
    json.updateString("gadget.title", "string value") catch {};
    json.updateString("gadget.link", "string value") catch {};
    json.updateString("gadget.iconLink", "string value") catch {};
    json.updateNumber("gadget.width", "1234") catch {};
    json.updateNumber("gadget.height", "1234") catch {};
    json.updateString("gadget.display", "string value") catch {};
    json.updateString("gadget.preferences.someKey", "string value") catch {};
    json.updateBool("anyoneCanAddSelf", true) catch {};
    json.updateBool("guestsCanInviteOthers", true) catch {};
    json.updateBool("guestsCanModify", true) catch {};
    json.updateBool("guestsCanSeeOtherGuests", true) catch {};
    json.updateBool("privateCopy", true) catch {};
    json.updateBool("locked", true) catch {};
    json.updateBool("reminders.useDefault", true) catch {};
    json.updateString("reminders.overrides[0].method", "string value") catch {};
    json.updateNumber("reminders.overrides[0].minutes", "1234") catch {};
    json.updateString("source.url", "string value") catch {};
    json.updateString("source.title", "string value") catch {};
    json.updateString("attachments[0].fileUrl", "string value") catch {};
    json.updateString("attachments[0].title", "string value") catch {};
    json.updateString("attachments[0].mimeType", "string value") catch {};
    json.updateString("attachments[0].iconLink", "string value") catch {};
    json.updateString("attachments[0].fileId", "string value") catch {};
    json.updateString("attachments[1].fileUrl", "string value") catch {};
    json.updateString("attachments[1].title", "string value") catch {};
    json.updateString("attachments[1].mimeType", "string value") catch {};
    json.updateString("attachments[1].iconLink", "string value") catch {};
    json.updateString("attachments[1].fileId", "string value") catch {};

    json.setEmitCompact(false);
    std.debug.print("{s}\n", .{try json.emit(alloc)});
}