Conversion functions in Jitterbit Integration Studio
Conversion functions are used to convert Jitterbit data elements and variables from one type to another.
BinaryToHex
Declaration
string BinaryToHex(binary arg)
Syntax
BinaryToHex(<arg>)
Required parameters
arg
: Binary value to be converted
Description
Converts a binary value to a string representing the hexadecimal values of each byte. The resulting string will be all lowercase. The result of this function call is undefined if the argument is not a binary value.
This is the reverse of the function HexToBinary
.
Examples
// If $x is a binary value containing the bytes
// 0x17 0xA3 0xEF 0x80
BinaryToHex($x)
// returns the string "17a3ef80"
// If $y is an empty binary value
BinaryToHex($y)
// returns an empty string ("")
BinaryToUUID
Declaration
string BinaryToUUID(binary arg)
Syntax
BinaryToUUID(<arg>)
Required parameters
arg
: Binary value to be converted
Description
Converts a 16-byte binary value to a string in the standard UUID format. The resulting string will always be lowercase.
This is the reverse of the function UUIDToBinary
.
Examples
// If $x is a binary value containing the 16 bytes
// 0x2F 0x46 0xDA 0xD9 0xE5 0xC2 0x45 0x7E 0xB1 0xFD 0xAD 0x1B 0x49 0xB9 0x9A 0xFF,
BinaryToUuid($x)
// returns the string "2f46dad9-e5c2-457e-b1fd-ad1b49b99aff"
Bool
Declaration
bool Bool(binary arg)
Syntax
Bool(<arg>)
Required parameters
arg
: Binary value to be converted
Description
Converts any data type to a boolean value (true
or false
). If the data is an integer or a floating-point number not equal to zero, the result is true
(1). The strings "true"
and "T"
return true independently of case ("TRUE"
, "t"
, and "True"
all return true
). In all other cases, the result is false
(0).
Examples
Bool(2);
// Returns true
Bool("true");
// Returns true
Bool("F");
// Returns false
Bool("text");
// Returns false
Date
Declaration
date Date(type arg)
Syntax
Date(<arg>)
Required parameters
arg
: Value to be converted to a date object
Description
Converts the argument to a date. If the input is a string, it has to be formatted using one of the standard date formats such as "12/25/2018 12:30"
,"2018-12-25"
, "2018-12-25T12:30:00"
,"December 25, 2018"
, or"DEC 25, 2018"
.
If the input string is not in one of the four predefined date formats (GeneralDate
, LongDate
, MediumDate
, or ShortDate
) that can be read by the Date
function, it can be converted first to a standard format by the CVTDate
function. Hour, minute, and second are optional.
If the input is an integer or a double, the input is interpreted as the number of seconds from 12:00:00 AM of 1/1/1970 UTC, the start of the UNIX epoch.
Note that Date(Long(Now())) == Now()
.
Examples
Date("9/27/2007");
// Returns the date that represents 2007-09-27 00:00:00 UTC
Date(1190888288);
// Returns the date that represents 2007-09-27 10:18:08 UTC
// (also known as 2007-09-27T10:18:08)
Double
Declaration
double Double(type arg)
Syntax
Double(<arg>)
Required parameters
arg
: Value to be converted
Description
A best-effort is made to convert the argument to a double. If the data type being evaluated cannot be converted to a double, the function returns 0. If the data being evaluated is a date or time record, the result is the number of seconds from 12:00:00 AM of 1/1/1970 UTC (the start of the UNIX epoch).
Examples
Double(19.9874);
// Returns a value of 19.987400
Double(9/15);
// Returns a value of 0
Double("5.5a");
// Returns a value of 5.5
Double("abcd");
// Returns 0
Double(Date("2007-09-27T10:18:08"));
// Returns 1190888288
Float
Declaration
float Float(type arg)
Syntax
Float(<arg>)
Required parameters
arg
: Value to be converted
Description
A best-effort is made to convert the argument to a float. If the data type being evaluated cannot be converted to a float the function returns 0. If the data being evaluated is a date or time record, the result is the number of seconds from 12:00:00 AM of 1/1/1970 UTC (the start of the UNIX epoch).
Examples
Float(345);
// Returns a value of 345
Float("3.141592");
// Returns a value of 3.14159
Float("5.5a");
// Returns a value of 5.5
Float("abcd");
// Returns 0
Float("2007-09-27T10:18:08");
// Returns 1.19089e+09
HexToBinary
Declaration
string HexToBinary(string arg)
Syntax
HexToBinary(<arg>)
Required parameters
arg
: Hex-string to be converted
Description
Converts a hex-string to a binary value. The resulting value will contain the bytes represented by each pair of characters in the input string. The input string is case-insensitive.
This is the reverse of the function BinaryToHex
.
Examples
HexToBinary("17a3ef80");
// Returns a binary value containing the bytes 0x17 0xA3 0xEF 0x80
HexToBinary("17A3EF80");
// Returns a binary value containing the bytes 0x17 0xA3 0xEF 0x80
HexToBinary("");
// Returns an empty binary value
HexToString
Declaration
string HexToString(string arg)
Syntax
HexToString(<arg>)
Required parameters
arg
: Hex-string element to be converted
Description
Converts a UTF-8 hex-string to a string value. The resulting value will contain the characters represented by each pair of characters in the input string. The input string is case-insensitive. As the input characters are hex, the character pairs of the input string must be limited to the range "00" through "FF".
To convert the outgoing string value from a UTF-16 hex-string, set jitterbit.scripting.hex.enable_unicode_support
to true
upstream of this function when using agent versions 10.71 / 11.9 or later.
This is the reverse of the function StringToHex
.
Examples
HexToString("6E6577");
// Returns "new"
HexToString("00");
// Returns an empty string ("")
HexToString("c2a7");
// Returns "§" (UTF-8)
HexToString("a7");
// Returns "§" if jitterbit.scripting.hex.enable_unicode_support is set to true (UTF-16), otherwise returns "�" (UTF-8)
Int
Declaration
int Int(type arg)
Syntax
Int(<arg>)
Required parameters
arg
: Value to be converted
Description
A best-effort is made to convert the argument to an integer. If the data type being evaluated cannot be converted to an integer, the function returns 0. If the data being evaluated is a date or time record, the result is the number of seconds from 12:00:00 AM of 1/1/1970 UTC (the start of the UNIX epoch).
Examples
Int("3.141592");
// Returns a value of 3
Int("5a");
// Returns a value of 5
Int("5");
// Returns a value of 5
Int("abcd");
// Returns 0
Int(Date("2007-09-27 10:18:08"));
// Returns a value of 1190888288
Long
Declaration
long Long(type arg)
Syntax
Long(<arg>)
Required parameters
arg
: Value to be converted
Description
A best-effort is made to convert the argument to a long integer. If the data type being evaluated cannot be converted to a long integer, the function returns 0. If the data being evaluated is a date or time record, the result is the number of seconds from 12:00:00 AM of 1/1/1970 UTC (the start of the UNIX epoch).
Examples
Long("3.141529");
// Returns a value of 3
Long("5a");
// Returns a value of 5
Long("5");
// Returns a value of 5
Long(1234567890.123456);
// Returns a value of 1234567890
Long("abcd");
// Returns a value of 0
Long(Date("2007-09-27 10:18:08"));
// Returns a value of 1190888288
String
Declaration
string String(type arg)
Syntax
String(<arg>)
Required parameters
arg
: Value to be converted
Description
Converts any data type to a string. If the data being evaluated is already a string, no conversion takes place.
If the data type is a date or time record, the date is returned in ISO 8601 format (yyyy-mm-dd HH:MM:SS). For other date formats, use the functions CVTDate
or FormatDate
.
Binary data that contains null bytes is returned as a string representing the hexadecimal values of each byte, just as if BinaryToHex
had been called. If the binary data contains no null bytes, then a string representation is returned with the assumption that the bytes represent a UTF-8-encoded string. If you always want a hexadecimal representation, use the BinaryToHex
function instead.
For a boolean value, the strings "1" or "0" are returned.
Examples
String("98");
// Returns a value of "98"
String(98);
// Returns a value of "98"
String(true);
// Returns a value of "1"
String(Date("2007-09-27T10:18:08"));
// Returns a value of "2007-09-27 10:18:08"
String(HexToBinary("6E6577"));
// Returns a value of "new"
StringToHex
Declaration
string StringToHex(string arg)
Syntax
StringToHex(<arg>)
Required parameters
arg
: String element to be converted
Description
Converts a string value to a UTF-8 hex-string. The resulting string will be all lowercase. The result of this function call is undefined if the argument is not a string value.
To convert the incoming string value to a UTF-16 hex-string, set jitterbit.scripting.hex.enable_unicode_support
to true
upstream of this function when using agent versions 10.71 / 11.9 or later.
This is the reverse of the function HexToString
.
Examples
StringToHex("new");
// Returns "6e6577"
StringToHex("");
// Returns an empty string ("")
StringToHex("§");
// Returns "a7" if jitterbit.scripting.hex.enable_unicode_support is set to true (UTF-16), otherwise returns "c2a7" (UTF-8)
UUIDToBinary
Declaration
binary UUIDToBinary(string arg)
Syntax
UUIDToBinary(<arg>)
Required parameters
arg
: String element to be converted
Description
Converts a UUID string to a binary value containing the corresponding bytes. The size of the input string must be 36 characters. The format of the input should be nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
where each pair (nn
) is the hexadecimal representation of the corresponding byte. The case of the input string does not matter. The returned binary value is 16 bytes long.
This is the reverse of the function BinaryToUID
.
Examples
UuidToBinary("2f46dad9-e5c2-457e-b1fd-ad1b49b99aff")
// returns a binary value with the bytes
// 0x2F 0x46 0xDA 0xD9 0xE5 0xC2 0x45 0x7E 0xB1 0xFD 0xAD 0x1B 0x49 0xB9 0x9A 0xFF