Class Utilities Stay organized with collections Save and categorize content based on your preferences.
Page Summary
The Utilities service in Apps Script provides various helper functions for common tasks like encoding, decoding, date formatting, and data manipulation.
It offers methods for base-64 encoding and decoding for both standard and web-safe formats with optional character set specification.
The service includes functions for computing message digests and HMAC/RSA signatures using various algorithms.
Utilities provides methods for formatting and parsing dates and strings, generating UUIDs, and creating or manipulating Blob objects for binary data.
Features for compressing and decompressing data using gzip and handling zip archives are also available.
This service provides utilities for string encoding/decoding, date formatting, JSON manipulation,and other miscellaneous tasks.
Properties
| Property | Type | Description |
|---|---|---|
Charset | Charset | |
Digest | Digest | |
Mac | Mac | |
Rsa | Rsa |
Methods
| Method | Return type | Brief description |
|---|---|---|
base64Decode(encoded) | Byte[] | Decodes a base-64 encoded string into a UTF-8 byte array. |
base64Decode(encoded, charset) | Byte[] | Decodes a base-64 encoded string into a byte array in a specific character set. |
base64DecodeWebSafe(encoded) | Byte[] | Decodes a base-64 web-safe encoded string into a UTF-8 byte array. |
base64DecodeWebSafe(encoded, charset) | Byte[] | Decodes a base-64 web-safe encoded string into a byte array in a specific character set. |
base64Encode(data) | String | Generates a base-64 encoded string from the given byte array. |
base64Encode(data) | String | Generates a base-64 encoded string from the given string. |
base64Encode(data, charset) | String | Generates a base-64 encoded string from the given string in a specific character set. |
base64EncodeWebSafe(data) | String | Generates a base-64 web-safe encoded string from the given byte array. |
base64EncodeWebSafe(data) | String | Generates a base-64 web-safe encoded string from the given string. |
base64EncodeWebSafe(data, charset) | String | Generates a base-64 web-safe encoded string from the given string in a specific character set. |
compute | Byte[] | Compute a digest using the specified algorithm on the specifiedByte[] value. |
compute | Byte[] | Compute a digest using the specified algorithm on the specifiedString value. |
compute | Byte[] | Compute a digest using the specified algorithm on the specifiedString value with thegiven character set. |
compute | Byte[] | Signs the provided value using HMAC-SHA256 with the given key. |
compute | Byte[] | Signs the provided value using HMAC-SHA256 with the given key. |
compute | Byte[] | Signs the provided value using HMAC-SHA256 with the given key and character set. |
compute | Byte[] | Compute a message authentication code using the specified algorithm on the specified key andvalue. |
compute | Byte[] | Compute a message authentication code using the specified algorithm on the specified key andvalue. |
compute | Byte[] | Compute a message authentication code using the specified algorithm on the specified key andvalue. |
compute | Byte[] | Signs the provided value using RSA-SHA1 with the given key. |
compute | Byte[] | Signs the provided value using RSA-SHA1 with the given key and charset. |
compute | Byte[] | Signs the provided value using RSA-SHA256 with the given key. |
compute | Byte[] | Signs the provided value using RSA-SHA256 with the given key. |
compute | Byte[] | Signs the provided value using the specified RSA algorithm with the given key. |
compute | Byte[] | Signs the provided value using the specified RSA algorithm with the given key and charset. |
format | String | Formats date according to specification described in Java SE SimpleDateFormat class. |
format | String | Performssprintf-like string formatting using '%'-style format strings. |
get | String | Get a UUID as a string (equivalent to using thejava.util.UUID.randomUUID() method). |
gzip(blob) | Blob | gzip-compresses the providedBlob data and returns it in a newBlob object. |
gzip(blob, name) | Blob | gzip-compresses the providedBlob data and returns it in a newBlob object. |
new | Blob | Create a new Blob object from a byte array. |
new | Blob | Create a new Blob object from a byte array and content type. |
new | Blob | Create a new Blob object from a byte array, content type, and name. |
new | Blob | Create a new Blob object from a string. |
new | Blob | Create a new Blob object from a string and content type. |
new | Blob | Create a new Blob object from a string, content type, and name. |
parse | String[][] | Returns a tabular 2D array representation of a CSV string. |
parse | String[][] | Returns a tabular 2D array representation of a CSV string using a custom delimiter. |
parse | Date | Parses the provided string date according to the specification described in the Java StandardEditionSimple class. |
sleep(milliseconds) | void | Sleeps for specified number of milliseconds. |
ungzip(blob) | Blob | Uncompresses aBlob object and returns aBlob containing the uncompresseddata. |
unzip(blob) | Blob[] | Takes a Blob representing a zip file and returns its component files. |
zip(blobs) | Blob | Creates a new Blob object that is a zip file containing the data from the Blobs passed in. |
zip(blobs, name) | Blob | Creates a new Blob object that is a zip file containing the data from the Blobs passed in. |
Deprecated methods
| Method | Return type | Brief description |
|---|---|---|
| Object | Return an object corresponding to the JSON string passed in. |
| String | Return a JSON string of the object passed in. |
Detailed documentation
base64Decode(encoded)
Decodes a base-64 encoded string into a UTF-8 byte array.
// This is the base64 encoded form of "Google グループ"constbase64data='R29vZ2xlIOOCsOODq+ODvOODlw==';// This logs:// [71, 111, 111, 103, 108, 101, 32, -29, -126, -80,// -29, -125, -85, -29, -125, -68, -29, -125, -105]constdecoded=Utilities.base64Decode(base64data);Logger.log(decoded);// If you want a String instead of a byte array:// This logs the original "Google グループ"Logger.log(Utilities.newBlob(decoded).getDataAsString());
Parameters
| Name | Type | Description |
|---|---|---|
encoded | String | An array of bytes of data to decode. |
Return
Byte[] — The raw data represented by the base-64 encoded argument as a byte array.
base64Decode(encoded, charset)
Decodes a base-64 encoded string into a byte array in a specific character set.
// This is the base64 encoded form of "Google グループ"constbase64data='R29vZ2xlIOOCsOODq+ODvOODlw==';constdecoded=Utilities.base64Decode(base64data,Utilities.Charset.UTF_8);// This logs:// [71, 111, 111, 103, 108, 101, 32, -29, -126, -80,// -29, -125, -85, -29, -125, -68, -29, -125, -105]Logger.log(decoded);// If you want a String instead of a byte array:// This logs the original "Google グループ"Logger.log(Utilities.newBlob(decoded).getDataAsString());
Parameters
| Name | Type | Description |
|---|---|---|
encoded | String | The string of data to decode. |
charset | Charset | ACharset specifying the charset of the input. |
Return
Byte[] — The raw data represented by the base-64 encoded argument as a byte array.
base64DecodeWebSafe(encoded)
Decodes a base-64 web-safe encoded string into a UTF-8 byte array.
// This is the base64 web-safe encoded form of "Google グループ"constbase64data='R29vZ2xlIOOCsOODq-ODvOODlw==';constdecoded=Utilities.base64DecodeWebSafe(base64data);// This logs:// [71, 111, 111, 103, 108, 101, 32, -29, -126, -80,// -29, -125, -85, -29, -125, -68, -29, -125, -105]Logger.log(decoded);// If you want a String instead of a byte array:// This logs the original "Google グループ"Logger.log(Utilities.newBlob(decoded).getDataAsString());
Parameters
| Name | Type | Description |
|---|---|---|
encoded | String | An array of bytes of web-safe data to decode. |
Return
Byte[] — The raw data represented by the base-64 web-safe encoded argument as a byte array.
base64DecodeWebSafe(encoded, charset)
Decodes a base-64 web-safe encoded string into a byte array in a specific character set.
// This is the base64 web-safe encoded form of "Google グループ"constbase64data='R29vZ2xlIOOCsOODq-ODvOODlw==';constdecoded=Utilities.base64DecodeWebSafe(base64data,Utilities.Charset.UTF_8,);// This logs:// [71, 111, 111, 103, 108, 101, 32, -29, -126, -80,// -29, -125, -85, -29, -125, -68, -29, -125, -105]Logger.log(decoded);// If you want a String instead of a byte array:// This logs the original "Google グループ"Logger.log(Utilities.newBlob(decoded).getDataAsString());
Parameters
| Name | Type | Description |
|---|---|---|
encoded | String | The string of web-safe data to decode. |
charset | Charset | ACharset specifying the charset of the input. |
Return
Byte[] — The raw data represented by the base-64 web-safe encoded argument as a byte array.
base64Encode(data)
Generates a base-64 encoded string from the given byte array. Base 64 is a common encodingaccepted by a variety of tools that cannot accept binary data. Base 64 is commonly used ininternet protocols such as email, HTTP, or in XML documents.
// Instantiates a blob here for clarityconstblob=Utilities.newBlob('A string here');// Writes 'QSBzdHJpbmcgaGVyZQ==' to the log.constencoded=Utilities.base64Encode(blob.getBytes());Logger.log(encoded);
Parameters
| Name | Type | Description |
|---|---|---|
data | Byte[] | A byte[] of data to encode. |
Return
String — The base-64 encoded representation of the passed in data.
base64Encode(data)
Generates a base-64 encoded string from the given string. Base 64 is a common encoding acceptedby a variety of tools that cannot accept binary data. Base 64 is commonly used in internetprotocols such as email, HTTP, or in XML documents.
// Writes 'QSBzdHJpbmcgaGVyZQ==' to the log.constencoded=Utilities.base64Encode('A string here');Logger.log(encoded);
Parameters
| Name | Type | Description |
|---|---|---|
data | String | The string to encode. |
Return
String — The base-64 encoded representation of the input string.
base64Encode(data, charset)
Generates a base-64 encoded string from the given string in a specific character set. A Charsetis a way of encoding characters such that they can be encoded. These are typically done in abinary format, which can generally be incompatible with certain data transmission protocols. Tomake the data compatible, they are generally encoded into base 64, which is a common encodingaccepted by a variety of tools that cannot accept binary data. Base 64 is commonly used ininternet protocols such as email, HTTP, or in XML documents.
// "Google Groups" in Katakana (Japanese)constinput='Google グループ';// Writes "R29vZ2xlIOOCsOODq+ODvOODlw==" to the logconstencoded=Utilities.base64Encode(input,Utilities.Charset.UTF_8);Logger.log(encoded);
Parameters
| Name | Type | Description |
|---|---|---|
data | String | The string of data to encode. |
charset | Charset | ACharset specifying the charset of the input. |
Return
String — The base-64 encoded representation of the input string with the givenCharset.
base64EncodeWebSafe(data)
Generates a base-64 web-safe encoded string from the given byte array. Base 64 is a commonencoding accepted by a variety of tools that cannot accept binary data. Base 64 web-safe iscommonly used in internet protocols such as email, HTTP, or in XML documents.
// Instantiates a blob here for clarityconstblob=Utilities.newBlob('A string here');// Writes 'QSBzdHJpbmcgaGVyZQ==' to the log.constencoded=Utilities.base64EncodeWebSafe(blob.getBytes());Logger.log(encoded);
Parameters
| Name | Type | Description |
|---|---|---|
data | Byte[] | An array of bytes of data to encode. |
Return
String — The base-64 web-safe encoded representation of the passed in data.
base64EncodeWebSafe(data)
Generates a base-64 web-safe encoded string from the given string. Base 64 is a common encodingaccepted by a variety of tools that cannot accept binary data. Base 64 web-safe is commonlyused in internet protocols such as email, HTTP, or in XML documents.
// Writes 'QSBzdHJpbmcgaGVyZQ==' to the log.constencoded=Utilities.base64EncodeWebSafe('A string here');Logger.log(encoded);
Parameters
| Name | Type | Description |
|---|---|---|
data | String | The string to encode. |
Return
String — The base-64 web-safe encoded representation of the input string.
base64EncodeWebSafe(data, charset)
Generates a base-64 web-safe encoded string from the given string in a specific character set.A Charset is a way of encoding characters such that they can be encoded. These are typicallydone in a binary format, which can generally be incompatible with certain data transmissionprotocols. To make the data compatible, they are generally encoded into base 64, which is acommon encoding accepted by a variety of tools that cannot accept binary data. Base 64 web-safeis commonly used in internet protocols such as email, HTTP, or in XML documents.
// "Google Groups" in Katakana (Japanese)constinput='Google グループ';// Writes "R29vZ2xlIOOCsOODq-ODvOODlw==" to the logconstencoded=Utilities.base64EncodeWebSafe(input,Utilities.Charset.UTF_8);Logger.log(encoded);
Parameters
| Name | Type | Description |
|---|---|---|
data | String | The string of data to encode. |
charset | Charset | ACharset specifying the charset of the input. |
Return
String — The base-64 web-safe encoded representation of the input string with the givenCharset.
computeDigest(algorithm, value)
Compute a digest using the specified algorithm on the specifiedByte[] value.
constinput=Utilities.base64Decode('aW5wdXQgdG8gaGFzaA0K');// == base64encode("input to hash")constdigest=Utilities.computeDigest(Utilities.DigestAlgorithm.MD5,input);Logger.log(digest);
Parameters
| Name | Type | Description |
|---|---|---|
algorithm | Digest | ADigest to use. |
value | Byte[] | An input string value to compute a digest for. |
Return
Byte[] — A byte[] representing the output digest.
computeDigest(algorithm, value)
Compute a digest using the specified algorithm on the specifiedString value.
constdigest=Utilities.computeDigest(Utilities.DigestAlgorithm.MD5,'input to hash',);Logger.log(digest);
Parameters
| Name | Type | Description |
|---|---|---|
algorithm | Digest | ADigest to use. |
value | String | An input string value to compute a digest for. |
Return
Byte[] — A byte[] representing the output digest.
computeDigest(algorithm, value, charset)
Compute a digest using the specified algorithm on the specifiedString value with thegiven character set.
constdigest=Utilities.computeDigest(Utilities.DigestAlgorithm.MD5,'input to hash',Utilities.Charset.US_ASCII,);Logger.log(digest);
Parameters
| Name | Type | Description |
|---|---|---|
algorithm | Digest | ADigest to use. |
value | String | An input string value to compute a digest for. |
charset | Charset | ACharset representing the input character set. |
Return
Byte[] — A byte[] representing the output digest.
computeHmacSha256Signature(value, key)
Signs the provided value using HMAC-SHA256 with the given key.
// This writes an array of bytes to the log.constinput=Utilities.base64Decode('aW5wdXQgdG8gaGFzaA0K');// == base64encode("input to hash")constkey=Utilities.base64Decode('a2V5');// == base64encode("key")constsignature=Utilities.computeHmacSha256Signature(input,key);Logger.log(signature);
Parameters
| Name | Type | Description |
|---|---|---|
value | Byte[] | The input value to generate a hash for. |
key | Byte[] | A key to use to generate the hash with. |
Return
Byte[] — A byte[] representing the output signature.
computeHmacSha256Signature(value, key)
Signs the provided value using HMAC-SHA256 with the given key.
// This writes an array of bytes to the log.constsignature=Utilities.computeHmacSha256Signature('this is my input','my key - use a stronger one',);Logger.log(signature);
Parameters
| Name | Type | Description |
|---|---|---|
value | String | The input value to generate a hash for. |
key | String | A key to use to generate the hash with. |
Return
Byte[] — A byte[] representing the output signature.
computeHmacSha256Signature(value, key, charset)
Signs the provided value using HMAC-SHA256 with the given key and character set.
// This writes an array of bytes to the log.constsignature=Utilities.computeHmacSha256Signature('this is my input','my key - use a stronger one',Utilities.Charset.US_ASCII,);Logger.log(signature);
Parameters
| Name | Type | Description |
|---|---|---|
value | String | The input value to generate a hash for. |
key | String | A key to use to generate the hash with. |
charset | Charset | ACharset representing the input character set. |
Return
Byte[] — A byte[] representing the output signature.
computeHmacSignature(algorithm, value, key)
Compute a message authentication code using the specified algorithm on the specified key andvalue.
// This writes an array of bytes to the log.constinput=Utilities.base64Decode('aW5wdXQgdG8gaGFzaA0K');// == base64encode("input to hash")constkey=Utilities.base64Decode('a2V5');// == base64encode("key")constsignature=Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_MD5,input,key,);Logger.log(signature);
Parameters
| Name | Type | Description |
|---|---|---|
algorithm | Mac | AMac algorithm to use to hash the input value. |
value | Byte[] | The input value to generate a hash for. |
key | Byte[] | A key to use to generate the hash with. |
Return
Byte[] — A byte[] representing the output signature.
computeHmacSignature(algorithm, value, key)
Compute a message authentication code using the specified algorithm on the specified key andvalue.
// This writes an array of bytes to the log.constsignature=Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_MD5,'input to hash','key',);Logger.log(signature);
Parameters
| Name | Type | Description |
|---|---|---|
algorithm | Mac | AMac algorithm to use to hash the input value. |
value | String | The input value to generate a hash for. |
key | String | A key to use to generate the hash with. |
Return
Byte[] — A byte[] representing the output signature.
computeHmacSignature(algorithm, value, key, charset)
Compute a message authentication code using the specified algorithm on the specified key andvalue.
// This writes an array of bytes to the log.constsignature=Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_MD5,'input to hash','key',Utilities.Charset.US_ASCII,);Logger.log(signature);
Parameters
| Name | Type | Description |
|---|---|---|
algorithm | Mac | AMac algorithm to use to hash the input value. |
value | String | The input value to generate a hash for. |
key | String | A key to use to generate the hash with. |
charset | Charset | ACharset representing the input character set. |
Return
Byte[] — A byte[] representing the output signature.
computeRsaSha1Signature(value, key)
Signs the provided value using RSA-SHA1 with the given key.
// This writes an array of bytes to the log.constsignature=Utilities.computeRsaSha1Signature('this is my input',PropertiesService.getScriptProperties().getProperty('YOUR_PRIVATE_KEY'),);Logger.log(signature);
Parameters
| Name | Type | Description |
|---|---|---|
value | String | The input value to generate a hash for. |
key | String | A PEM formatted key to use to generate the signature. |
Return
Byte[] — A byte[] representing the output signature.
computeRsaSha1Signature(value, key, charset)
Signs the provided value using RSA-SHA1 with the given key and charset.
// This writes an array of bytes to the log.constsignature=Utilities.computeRsaSha1Signature('this is my input',PropertiesService.getScriptProperties().getProperty('YOUR_PRIVATE_KEY'),Utilities.Charset.US_ASCII,);Logger.log(signature);
Parameters
| Name | Type | Description |
|---|---|---|
value | String | The input value to generate a hash for. |
key | String | A PEM formatted key to use to generate the signature. |
charset | Charset | ACharset representing the input character set. |
Return
Byte[] — A byte[] representing the output signature.
computeRsaSha256Signature(value, key)
Signs the provided value using RSA-SHA256 with the given key.
// This writes an array of bytes to the log.constsignature=Utilities.computeRsaSha256Signature('this is my input',PropertiesService.getScriptProperties().getProperty('YOUR_PRIVATE_KEY'),);Logger.log(signature);
Parameters
| Name | Type | Description |
|---|---|---|
value | String | The input value to generate a hash for. |
key | String | A PEM formatted key to use to generate the signature. |
Return
Byte[] — A byte[] representing the output signature.
computeRsaSha256Signature(value, key, charset)
Signs the provided value using RSA-SHA256 with the given key.
// This writes an array of bytes to the log.constsignature=Utilities.computeRsaSha256Signature('this is my input',PropertiesService.getScriptProperties().getProperty('YOUR_PRIVATE_KEY'),);Logger.log(signature);
Parameters
| Name | Type | Description |
|---|---|---|
value | String | The input value to generate a hash for. |
key | String | A PEM formatted key to use to generate the signature. |
charset | Charset | ACharset representing the input character set. |
Return
Byte[] — A byte[] representing the output signature.
computeRsaSignature(algorithm, value, key)
Signs the provided value using the specified RSA algorithm with the given key.
// This writes an array of bytes to the log.constsignature=Utilities.computeRsaSignature(Utilities.RsaAlgorithm.RSA_SHA_256,'this is my input',PropertiesService.getScriptProperties().getProperty('YOUR_PRIVATE_KEY'),);Logger.log(signature);
Parameters
| Name | Type | Description |
|---|---|---|
algorithm | Rsa | ARsa algorithm to use to hash the input value. |
value | String | The input value to generate a hash for. |
key | String | A PEM formatted key to use to generate the signature. |
Return
Byte[] — A byte[] representing the output signature.
computeRsaSignature(algorithm, value, key, charset)
Signs the provided value using the specified RSA algorithm with the given key and charset.
// This writes an array of bytes to the log.constsignature=Utilities.computeRsaSignature(Utilities.RsaAlgorithm.RSA_SHA_256,'this is my input',PropertiesService.getScriptProperties().getProperty('YOUR_PRIVATE_KEY'),Utilities.Charset.US_ASCII,);Logger.log(signature);
Parameters
| Name | Type | Description |
|---|---|---|
algorithm | Rsa | ARsa algorithm to use to hash the input value. |
value | String | The input value to generate a hash for. |
key | String | A PEM formatted key to use to generate the signature. |
charset | Charset | ACharset representing the input character set. |
Return
Byte[] — A byte[] representing the output signature.
formatDate(date, timeZone, format)
Formats date according to specification described in Java SE SimpleDateFormat class. Pleasevisit the specification athttp://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
// This formats the date as Greenwich Mean Time in the format// year-month-dateThour-minute-second.constformattedDate=Utilities.formatDate(newDate(),'GMT','yyyy-MM-dd\'T\'HH:mm:ss\'Z\'',);Logger.log(formattedDate);
Parameters
| Name | Type | Description |
|---|---|---|
date | Date | ADate to format as a String. |
time | String | The output timezone of the result. |
format | String | A format per theSimple specification. |
Return
String — The input date as a formatted string.
formatString(template, args)
Performssprintf-like string formatting using '%'-style format strings.
// " 123.456000"Utilities.formatString('%11.6f',123.456);// " abc"Utilities.formatString('%6s','abc');
Parameters
| Name | Type | Description |
|---|---|---|
template | String | The format string that controls what gets returned. |
args | Object... | Objects to use to fill in the '%' placeholders in the template. |
Return
String — The formatted string.
getUuid()
Get a UUID as a string (equivalent to using thejava.util.UUID.randomUUID() method). This identifier is not guaranteed to be unique acrossall time and space. As such, do not use in situations where guaranteed uniqueness is required.
// This assigns a UUID as a temporary ID for a data object you are creating in// your script.constmyDataObject={tempId:Utilities.getUuid(),};
Return
String — A string representation of the UUID.
gzip(blob)
gzip-compresses the providedBlob data and returns it in a newBlob object.
consttextBlob=Utilities.newBlob('Some text to compress using gzip compression',);// Create the compressed blob.constgzipBlob=Utilities.gzip(textBlob);
Parameters
| Name | Type | Description |
|---|---|---|
blob | Blob | ABlob object to compress usinggzip. |
Return
gzip(blob, name)
gzip-compresses the providedBlob data and returns it in a newBlob object. This version of the method allows a filename to be specified.
consttextBlob=Utilities.newBlob('Some text to compress using gzip compression',);// Create the compressed blob.constgzipBlob=Utilities.gzip(textBlob,'text.gz');
Parameters
| Name | Type | Description |
|---|---|---|
blob | Blob | ABlob object to compress usinggzip. |
name | String | The name of thegzip file to be created. |
Return
newBlob(data)
Create a new Blob object from a byte array. Blobs are used in many Apps Script APIs that takebinary data as input.
// Creates a blob object from a byte array.constdata=[71,79,79,71,76,69];constblob=Utilities.newBlob(data);// Logs the blob data as a string to the console.console.log(blob.getDataAsString());
Parameters
| Name | Type | Description |
|---|---|---|
data | Byte[] | The bytes for the blob. |
Return
Blob — The newly created Blob.
newBlob(data, contentType)
Create a new Blob object from a byte array and content type. Blobs are used in many Apps ScriptAPIs that take binary data as input.
// Declares a byte array.constdata=[71,79,79,71,76,69];// Declares the content type of the blob.constcontentType='application/json';// Creates a blob object from the byte array and content type.constblob=Utilities.newBlob(data,contentType);// Logs the blob data as a string to the console.console.log(blob.getDataAsString());// Logs the content type of the blob to the console.console.log(blob.getContentType());
Parameters
| Name | Type | Description |
|---|---|---|
data | Byte[] | The bytes for the blob. |
content | String | The content type of the blob - can benull. |
Return
Blob — The newly created Blob.
newBlob(data, contentType, name)
Create a new Blob object from a byte array, content type, and name. Blobs are used in many AppsScript APIs that take binary data as input.
// Declares a byte array.constdata=[71,79,79,71,76,69];// Declares the content type of the blob.constcontentType='application/json';// Declares the name of the blob.constname='Example blob';// Creates a blob object from the byte array, content type, and name.constblob=Utilities.newBlob(data,contentType,name);// Logs the blob data as a string to the console.console.log('Blob data:',blob.getDataAsString());// Logs the content type of the blob to the console.console.log('Blob content type:',blob.getContentType());// Logs the name of the blob to the console.console.log('Blob name:',blob.getName());
Parameters
| Name | Type | Description |
|---|---|---|
data | Byte[] | The bytes for the blob. |
content | String | - The content type of the blob - can benull. |
name | String | The name of the blob - can benull. |
Return
Blob — The newly created Blob.
newBlob(data)
Create a new Blob object from a string. Blobs are used in many Apps Script APIs that takebinary data as input.
// Declares a string for the blob.constdata='GOOGLE';// Creates a blob object from a string.constblob=Utilities.newBlob(data);// Logs the blob data in byte array to the console.console.log('Blob Data:',blob.getBytes());
Parameters
| Name | Type | Description |
|---|---|---|
data | String | The string for the blob, assumed UTF-8. |
Return
Blob — The newly created Blob.
newBlob(data, contentType)
Create a new Blob object from a string and content type. Blobs are used in many Apps ScriptAPIs that take binary data as input.
// Declares a string for the blob.constdata='GOOGLE';// Declares the content type of blob.constcontentType='application/json';// Creates a blob object from the string and content type.constblob=Utilities.newBlob(data,contentType);// Logs the blob data in byte array to the console.console.log('Blob data:',blob.getBytes());// Logs the content type of the blob to the console.console.log(blob.getContentType());
Parameters
| Name | Type | Description |
|---|---|---|
data | String | The string for the blob, assumed UTF-8. |
content | String | The content type of the blob - can benull. |
Return
Blob — The newly created Blob.
newBlob(data, contentType, name)
Create a new Blob object from a string, content type, and name. Blobs are used in many AppsScript APIs that take binary data as input.
// Declares a string for the blob.constdata='GOOGLE';// Declares the content type of the blob.constcontentType='application/json';// Declares the name of the blob.constname='Example blob';// Create a blob object from the string, content type, and name.constblob=Utilities.newBlob(data,contentType,name);// Logs the blob data in byte array to the console.console.log('Blob data:',blob.getBytes());// Logs the content type of the blob to the console.console.log('Blob content type:',blob.getContentType());// Logs the name of the blob to the console.console.log('Blob name:',blob.getName());
Parameters
| Name | Type | Description |
|---|---|---|
data | String | The string for the blob, assumed UTF-8. |
content | String | The content type of the blob - can benull. |
name | String | The name of the blob - can benull. |
Return
Blob — The newly created Blob.
parseCsv(csv)
Returns a tabular 2D array representation of a CSV string.
// This creates a two-dimensional array of the format [[a, b, c], [d, e, f]]constcsvString='a,b,c\nd,e,f';constdata=Utilities.parseCsv(csvString);
Parameters
| Name | Type | Description |
|---|---|---|
csv | String | A string containing a single or multiline data in comma-separated value (CSV) format. |
Return
String[][] — A two-dimensional array containing the values in the CSV string.
parseCsv(csv, delimiter)
Returns a tabular 2D array representation of a CSV string using a custom delimiter.
// This creates a two-dimensional array of the format [[a, b, c], [d, e, f]]constcsvString='a\tb\tc\nd\te\tf';constdata=Utilities.parseCsv(csvString,'\t');
Parameters
| Name | Type | Description |
|---|---|---|
csv | String | A string containing a single or multiline data in comma-separated value (CSV) format. |
delimiter | Char | Between values. |
Return
String[][] — A two-dimensional array containing the values in the CSV string.
parseDate(date, timeZone, format)
Parses the provided string date according to the specification described in the Java StandardEditionSimple class. For more information, see the JavaSimple class.
// This set of parameters parses the given string as a date in Greenwich Mean// Time, formatted as year-month-dateThour-minute-second.constdate=Utilities.parseDate('1970-01-01 00:00:00','GMT','yyyy-MM-dd\' \'HH:mm:ss',);Logger.log(date);
Parameters
| Name | Type | Description |
|---|---|---|
date | String | A string value to parse as a date. |
time | String | The output time zone. |
format | String | The date format per theSimple specification. |
Return
Date — The input string as a date.
sleep(milliseconds)
Sleeps for specified number of milliseconds. Immediately puts the script to sleep for thespecified number of milliseconds. The maximum allowed value is 300000 (or 5 minutes).
// Creates a blob object from a string.constdata='GOOGLE';constblob=Utilities.newBlob(data);// Puts the script to sleep for 10,000 milliseconds (10 seconds).Utilities.sleep(10000);// Logs the blob data in byte array to the console.console.log(blob.getBytes());
Parameters
| Name | Type | Description |
|---|---|---|
milliseconds | Integer | The number of milliseconds to sleep. |
ungzip(blob)
Uncompresses aBlob object and returns aBlob containing the uncompresseddata.
consttextBlob=Utilities.newBlob('Some text to compress using gzip compression',);// Create the compressed blob.constgzipBlob=Utilities.gzip(textBlob,'text.gz');// Uncompress the data.constuncompressedBlob=Utilities.ungzip(gzipBlob);
Parameters
| Name | Type | Description |
|---|---|---|
blob | Blob | TheBlob of compressed data. |
Return
unzip(blob)
Takes a Blob representing a zip file and returns its component files.
constgoogleFavIconUrl='https://www.google.com/favicon.ico';constgoogleLogoUrl='https://www.google.com/images/srpr/logo3w.png';// Fetch the Google favicon.ico file and get the Blob dataconstfaviconBlob=UrlFetchApp.fetch(googleFavIconUrl).getBlob();constlogoBlob=UrlFetchApp.fetch(googleLogoUrl).getBlob();// zip now references a blob containing an archive of both faviconBlob and// logoBlobconstzip=Utilities.zip([faviconBlob,logoBlob],'google_images.zip');// This now unzips the blobsconstfiles=Utilities.unzip(zip);
Parameters
| Name | Type | Description |
|---|---|---|
blob | Blob | The zip file blob. |
Return
Blob[] — A Blob[] representing the component blobs, each named with the full path inside the zip.
zip(blobs)
Creates a new Blob object that is a zip file containing the data from the Blobs passed in.
constgoogleFavIconUrl='https://www.google.com/favicon.ico';constgoogleLogoUrl='https://www.google.com/images/srpr/logo3w.png';// Fetch the Google favicon.ico file and get the Blob dataconstfaviconBlob=UrlFetchApp.fetch(googleFavIconUrl).getBlob();constlogoBlob=UrlFetchApp.fetch(googleLogoUrl).getBlob();// zip now references a blob containing an archive of both faviconBlob and// logoBlobconstzip=Utilities.zip([faviconBlob,logoBlob]);
Parameters
| Name | Type | Description |
|---|---|---|
blobs | Blob | A array of blobs to zip up. |
Return
Blob — A new blob containing the inputs as an archive.
zip(blobs, name)
Creates a new Blob object that is a zip file containing the data from the Blobs passed in. Thisversion of the method allows a filename to be specified.
constgoogleFavIconUrl='https://www.google.com/favicon.ico';constgoogleLogoUrl='https://www.google.com/images/srpr/logo3w.png';// Fetch the Google favicon.ico file and get the Blob dataconstfaviconBlob=UrlFetchApp.fetch(googleFavIconUrl).getBlob();constlogoBlob=UrlFetchApp.fetch(googleLogoUrl).getBlob();// zip now references a blob containing an archive of both faviconBlob and// logoBlobconstzip=Utilities.zip([faviconBlob,logoBlob],'google_images.zip');
Parameters
| Name | Type | Description |
|---|---|---|
blobs | Blob | A array of blobs to zip up. |
name | String | The name of the zip file to be created. |
Return
Blob — A new blob containing the inputs as an archive.
Deprecated methods
jsonParse(jsonString)
jsonParse(jsonString) Deprecated. As of November 2013, replaced byJSON.parse()
Return an object corresponding to the JSON string passed in.
// Returns the object { name: "John Smith", company: "Virginia Company"}constobj=Utilities.jsonParse('{"name":"John Smith","company":"Virginia Company"}',);
Parameters
| Name | Type | Description |
|---|---|---|
json | String | A String representation of a JavaScript object to deserialize. |
Return
Object — A JavaScript object representation of the input.
jsonStringify(obj)
jsonStringify(obj) Deprecated. As of November 2013, replaced byJSON.stringify()
Return a JSON string of the object passed in.
// Logs: {"name":"John Smith","company":"Virginia Company"}constperson={name:'John Smith',company:'Virginia Company',};constjson=Utilities.jsonStringify(person);Logger.log(json);
Parameters
| Name | Type | Description |
|---|---|---|
obj | Object | the JavaScript object to serialize to JSON |
Return
String — a JSON serialized JavaScript object
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.