Creating a string using parts of other strings - 8.0

Talend Data Mapper Functions Reference Guide

Version
8.0
Language
English
Product
Talend Big Data Platform
Talend Data Fabric
Talend Data Management Platform
Talend Data Services Platform
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Design and Development > Designing Jobs
Last publication date
2023-10-26

Create a new string by modifying other strings using the LowerCase, Concat and Substring functions.

Before you begin

You have created a map with an input and an output structure. You can use the samples provided below.

About this task

In this example, you have a JSON file with users' first and last names. You want to generate a user ID, all in lowercase, composed of the full last name and the first two letters of the first name. You can use the following JSON sample as input:
{
	"users": [
		{
			"lastName": "Doe",
			"firstName": "John"
		},
		{
			"lastName": "Smith",
			"firstName": "Jane"
		},
		{
			"lastName": "Scott",
			"firstName": "Michael"
		}
	]
}
You can use the following JSON sample to create your output structure:
{
	"users": [
		{
			"lastName": "",
			"firstName": "",
			"id": ""
		}
	]
}

Procedure

  1. Drag and drop the input users element on the corresponding output element to map lastName and firstName.
  2. Drag and drop a LowerCase function on the output id element.
  3. Add a Concat function on the InputValue attribute of the LowerCase function.
  4. Drag and drop the input lastName element on the Concat function.
  5. Add a Substring function on the Concat function, under lastName.
  6. Drag and drop the input firstName element on the Input Value attribute of the Substring function.
  7. Double-click the Substring function to configure its properties:
    1. Enter 1 in the Start field to indicate that the substring should start with the first character of the firstName element.
    2. Enter 2 in the Length field to indicate that the substring should have a length of two characters.
  8. Click OK.

Results

Your map is configured and should look like this:
You can use the Test Run feature to see the result. In this example, the following output is returned:
{
    "users": [
        {
            "lastName": "Doe",
            "firstName": "John",
            "id": "doejo"
        },
        {
            "lastName": "Smith",
            "firstName": "Jane",
            "id": "smithja"
        },
        {
            "lastName": "Scott",
            "firstName": "Michael",
            "id": "scottmi"
        }
    ]
}