Function: json.decode

Decodes given JSON bytes (assuming UTF-8), or a string, into an object.

If the input is bytes, it is first converted to a string, as if by calling text.decode(data, 'UTF-8').

Arguments

Arguments
data

bytes|string

The input to be decoded.

Returns

The decoded object.

Raised exceptions

Exceptions
ValueError If given data is not a valid JSON object.

Examples

For more information, see Returning bytes.

# Decode Base64-encoded string to bytes, then decode bytes to object
- init:
    assign:
      - project: '${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}'
      - subscription: SUBSCRIPTION_ID
- pullMessage:  # pulls Pub/Sub message
    call: googleapis.pubsub.v1.projects.subscriptions.pull
    args:
        subscription: '${"projects/" + project + "/subscriptions/" + subscription}'
        body:
            maxMessages: 1
    result: m
- outputMessage:
    return: '${json.decode(base64.decode(m.receivedMessages[0].message.data))}'

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.