Sample code for 30+ languages & platforms
Zig

Get the JWS Payload into a StringBuilder

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.GetPayloadSb, which writes the payload of a loaded JWS as text into a StringBuilder, decoded using the given charset.

Background. In practice, validate the signature before trusting the payload.

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();

    const jws = try chilkat.Jws.init();
    defer jws.deinit();

    // Load the JWS compact serialization.
    const jws_compact = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>";
    jws.loadJws(jws_compact) catch {
        std.debug.print("{s}\n", .{try jws.getLastErrorText(alloc)});
        return;
    };

    // Get the JWS payload as text into a StringBuilder, decoded using the given charset.
    const sb_payload = try chilkat.StringBuilder.init();
    defer sb_payload.deinit();
    jws.getPayloadSb("utf-8", sb_payload) catch {
        std.debug.print("{s}\n", .{try jws.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("{s}\n", .{try sb_payload.getAsString(alloc)});
}