Scenario: Writing flat data into JSON fields - 6.1

Talend Components Reference Guide

Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
Talend Studio
Data Governance
Data Quality and Preparation
Design and Development

In this scenario, flat data is wrapped into JSON fields via tWriteJSONField.

Linking the components

  1. Drop the following components from the Palette onto the design workspace: tFixedFlowInput, tWriteJSONField and tLogRow.

  2. Link tFixedFlowInput and tWriteJSONField using a Row > Main connection.

  3. Link tWriteJSONField and tLogRow using a Row > Main connection.

Configuring the components

  1. Double-click tFixedFlowInput to display its Basic settings view.

  2. Click Edit schema to open the schema editor.

    Click the [+] button to add three columns, namely firstname, lastname and dept, with the type of string.

    Click OK to close the editor.

  3. Select the Use Inline Content option and enter the data below in the Content box:

  4. Click tWriteJSONField to display its Basic settings view.

    Select the Remove root node option to remove the root node setting from the JSON fields generated.

  5. Click Configure JSON Tree to open the XML tree editor.

    The schema of tFixedFlowInput appears in the Linker source panel.

  6. In the Linker target panel, click the default rootTag and type in staff, which is the root node of the JSON field to be generated.

  7. Right-click staff and select Add Sub-element from the context menu.

  8. In the pop-up box, enter the sub-node name, namely firstname.

    Repeat the steps to add two more sub-nodes, namely lastname and dept.

  9. Right-click firstname and select Set As Loop Element from the context menu.

  10. Drop firstname from the Linker source panel to its counterpart in the Linker target panel.

    In the pop-up dialog box, select Add linker to target node.

    Click OK to close the dialog box.

    Repeat the steps to link the two other items.

    Click OK to close the XML tree editor.

  11. Click Edit schema to open the schema editor.

  12. Click the [+] button in the right panel to add one column, namely staff, which will hold the JSON data generated.

    Click OK to close the editor.

  13. Double-click tLogRow to display its Basic settings view.

    Select Table (print values in cells of a table) for a better display of the results.

Executing the Job

  1. Press Ctrl + S to save the Job.

  2. Click F6 to execute the Job.

    As shown above, the JSON fields have been generated correctly, with the root node settings removed.