Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oJws
LOCAL cJwsCompact
LOCAL oSbPayload

nSuccess := 0

oJws := CreateObject("Chilkat.Jws")

//  Load the JWS compact serialization.
cJwsCompact := "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>"
nSuccess := oJws:LoadJws(cJwsCompact)
IF (nSuccess == 0)
    ? oJws:LastErrorText
    oJws:destroy()
    RETURN
ENDIF

//  Get the JWS payload as text into a StringBuilder, decoded using the given charset.
oSbPayload := CreateObject("Chilkat.StringBuilder")
nSuccess := oJws:GetPayloadSb("utf-8", oSbPayload)
IF (nSuccess == 0)
    ? oJws:LastErrorText
    oJws:destroy()
    oSbPayload:destroy()
    RETURN
ENDIF

? oSbPayload:GetAsString()

oJws:destroy()
oSbPayload:destroy()