Sample code for 30+ languages & platforms
Java

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

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Jws;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        Jws jws = new Jws();

        // Load the JWS compact serialization.
        String jwsCompact = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>";
        try {
            jws.loadJws(jwsCompact);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Get the JWS payload as text into a StringBuilder, decoded using the given charset.
        StringBuilder sbPayload = new StringBuilder();
        try {
            jws.getPayloadSb("utf-8", sbPayload);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println(sbPayload.getAsString());
    }
}