# Transforming your data

Talend Cloud API Tester allows you to manipulate data via functions.

Functions can create new data or transform existing data. The functions that transform data apply on the value of the expression they finish.

## Usage examples

If you want to retrieve the first 10 planet names in the list of planets in your Star Wars API, you can use the expression: ${"Star-wars API"."Get 10 planet names"."response"."body".jsonPath("$.results[:10].name")}. The method jsonPath parses the result of the expression ${"Star-wars API"."Get 10 planet names"."response"."body"}.

If you want to retrieve logs from the past week, you can create a URL with expressions in the query parameters: https://myapi.com/logs?from=${timestamp().addTime("WEEK", "-1")}&to=${timestamp()}.

If you want to generate the current date in ISO format, you can use the expression ${timestamp().formatDate('TIMESTAMP', 'ISO\_8601')}.

## Constants

When writing an expression like ${"toto"}, the expression is evaluated as:

* The value of the current environment's variable toto if there is one.
* The request/scenario/service/project toto that is at root-level in your repository if no environment variable matched.
* The string toto in any other case.

## Data creation functions

| Function | Description | Arguments | Example |
| --- | --- | --- | --- |
| timestamp | Returns the number of milliseconds from January 1, 1970, 00:00:00 GMT to the<br>date when it is evaluated. | none | Expression: ${timestamp()}<br><br>Possible result: 1505136142950 |
| uuid | Returns a UUID. | none | Expression: ${uuid()}<br><br>Possible result: f5fafd92-2298-4e72-97c9-df4dabaf27d2 |
| random | Returns a random number in range 0 &lt;=<br>number &lt; max. | Maximum: defaults to 1000000000 | Expression: ${random(50)}<br><br>Possible result: 42 |
| randomString | Returns a random string with a specific length.<br><br>Information noteNote: This function is not reliable for password generation and should not be<br>used for this purpose. | Length: number of characters in the string. Defaults to 10.<br><br><br>[a-z]: select this check box to include lowercase<br>letters in the string.<br><br><br>[A-Z]: select this check box to include uppercase<br>letters.<br><br><br>[0-9]: select this check box to include<br>numbers. | Expression: ${randomString(10, true, true, true)}<br><br>Possible result: 4ptUKhHYMr |

## Data transformation functions

| Function | Description | Arguments | Example |
| --- | --- | --- | --- |
| base64 | Encodes in base 64. | none | Expression: ${"username:password".base64()}<br><br>Result: dXNlcm5hbWU6cGFzc3dvcmQ= |
| lower | Converts all the characters to lower case using the rules of the default<br>locale. | none | Expression: ${"AbC".lower()}<br><br>Result: abc |
| length | Computes the length of its input:<br><br><ul> <li>the number of characters if the input is a string</li> <li>the number of items in a JSON array</li> <li>the number of keys in an JSON object</li> </ul> | none | Expression: ${"Star-wars API"."Get 2<br>planets"."response"."body"}<br><br>Result:<br><br>```<br>{<br>"count":61,<br>"results": [<br>{"name":"Alderaan" },<br>{"name":"Naboo" },<br>{"name":"Hoth" }<br>]<br>}<br>```<br><br>Expression: ${"Star-wars API"."Get 2<br>planets"."response"."body".length()}<br><br>Result: 2 Expression: ${"Star-wars<br>API"."Get 2<br>planets"."response"."body"."results".length()}<br><br>Result:<br>3<br><br>Expression: ${"Star-wars API"."Get 2<br>planets"."response"."body"."results"."0"."name".length()}<br><br>Result: 8 |
| substring | Returns a truncated input. | Start: position of the first character that should be<br>extracted (0 by default).<br><br><br>End: position of the first character that should be<br>omitted (end of the input by default).<br><br>Information noteNote: The index of the<br>first character is 0. | Expression: ${"0123456".substring(1)}<br><br>Result: 123456<br><br>Expression: ${"0123456".substring(1, 2)}<br><br>Result: 1<br><br>Expression: ${"0123456".substring(0, 4)} Result:<br>0123 |
| jsonPath | Returns the elements extracted from the JSON input with the given JSON path<br>selector. | Selector: The JSON path selector that points to the part of the JSON to<br>extract from the input. | Expression: ${"{\"titi\":<br>\"toto\"}".jsonPath("$.titi")}<br><br>Result: toto |
| xPath | Returns the elements extracted from the XML input with the given XPath<br>selector. | Selector: The XPath selector that points to the part of the XML<br>to extract from the input. | Expression: ${"&lt;title lang="en"<br>/&gt;".xPath("//title/@lang")}<br><br>Result: [lang="en"] |
| hmac | Creates a [Hash-based Message Authentication Code](https://en.wikipedia.org/wiki/Hash-based_message_authentication_code). | Cipher: the hash function (SHA1,<br>SHA224, SHA256, SHA384 or<br>SHA512). Secret<br><br>: the secret key.<br><br><br>Output: the output type (Base64 or<br>Hex). | Expression: ${"test".hmac("sha256",<br>"secret", "Base64")}<br><br>Result: Aymga2LNFrM+tnkr6MYLFY2Jou46h2/Omogeu0iMCRQ=<br><br>Expression: ${"test".hmac("sha1",<br>"secret", "Hex")}<br><br>Result: 1aa349585ed7ecbd3b9c486a30067e395ca4b356 |
| sha | Hashes its input. | Cipher: the hash function (SHA1,<br>SHA224, SHA256, SHA384 or<br>SHA512).<br><br><br>Output: the output type (Base64 or<br>Hex). | Expression: ${"toto".sha("SHA224",<br>"Base64")}<br><br>Result: IcBD7s1+hUI6ctrjwGKitb+g5rNc4/54jJtXpg==<br><br>Expression: ${"toto".sha("SHA1",<br>"Hex")}<br><br>Result: 0b9c2625dc21ef05f6ad4ddf47c5f203837aa32c |
| md5 | Calculates the MD5 hash of its input. | none | Expression: ${"toto".md5()}<br><br>Result: f71dbe52628a3f83a77ab494817525c6 |
| upper | Converts all the characters to upper case using the rules of the default<br>locale. | none | Expression: ${"aBc".upper()}<br><br>Result: ABC |
| string | Quotes its input. | Quotes: the character that should be used to quote the<br>input. (' or ", " is<br>used by default). | Expression: ${"toto".string()}<br><br>Result: "toto"<br><br>Expression:<br>${"toto".string("\"")}<br><br>Result: "toto"<br><br>Expression: ${"toto".string("'")}<br><br>Result: 'toto' |
| math | Performs the selected operation on the input value. | Operation: ADD, SUBTRACT,<br>MULTIPLY or DIVIDE<br><br><br>Value: number | Expression: ${"7".math("MULTIPLY",<br>"6")}<br><br>Result: 42<br><br>Expression: ${"3.14".math("ADD",<br>"0.00159265")}<br><br>Result: 3.14159265<br><br>Expression: ${"100".math("DIVIDE",<br>"-5")}<br><br>Result: -20 |
| addTime | Adds or removes a number of the selected time unit from a<br>date. | Time unit: YEAR, MONTH,<br>WEEK, DAY, HOUR,<br>MINUTE or SECOND<br><br><br>Value: integer (you can use a negative number to remove<br>a time unit) | Expression: ${timestamp().addTime("YEAR",<br>"1")}<br><br>Possible result: 1620292896490<br><br>Expression: ${timestamp().addTime("WEEK",<br>"-2")}<br><br>Possible result: 1587547696437 |
| formatDate | Converts a date into the selected format. | Input format: TIMESTAMP or<br>ISO\_8601<br><br><br>Output format: TIMESTAMP or<br>ISO\_8601 | Expression: ${timestamp().formatDate("TIMESTAMP",<br>"ISO\_8601")}<br><br>Possible result: 2020-05-06T13:43:22.248Z<br><br>Expression:<br>${"2020-04-06T13:44:51.435Z".formatDate("ISO\_8601",<br>"TIMESTAMP")}<br><br>Result: 1586180691435 |