Translate JSON item fields (names and values) into XML tags and values

Four Stars

Translate JSON item fields (names and values) into XML tags and values

Hi,

I have the implement the following: job data comes in JSON format and is transferred to another system in XML format.

A simplified sample of input looks like this:

 

[
   {
         "job": {
         "title": "test job",
         "items": [
            {
               "item": {
                  "type": "list",
                  "name": "MGR_MAIL",
                  "value": [
                     "manager@company.com"
                  ]
               }
            },
            {
               "item": {
                  "type": "string",
                  "name": "JOB_TYPE",
                  "value": "permanent"
               }
            },
            {
               "item": {
                  "type": "date",
                  "name": "JOB_START_DATE",
                  "value": "2018-08-07T20:00:00.000Z"
               }
            }
         ]
      }
   }
]

 

The output should be something like this:

 

<Data>
    <Job>
	<JobTitle>"test job"</JobTitle>
	<JOB_TYPE>"permanent"</JOB_TYPE>
        <JOB_START_DATE>2018-08-07</JOB_START_DATE> 
        <ManagerInfo>
            <MGR_MAIL>
                <EmailAddress>"manager@company.com"</EmailAddress> 
            </MGR_MAIL>
        </ManagerInfo>
    </Job>
</Data>

 

I am struggling with translating the item names and values into XML tags and values.

The number of items is around 40, and may not be always the same.

There are two situations:

1. Item name in json corresponds to the xml tags.
2. Item name in json does not correspond to the xml tags.

Could anyone provide some guidance how to deal with either of these cases?

Please see attached what I tried. It is not elegant, and I'm not sure how to proceed with the results in tLogRow_3 to transpose them. After that, I plan to merge with tLogRow_2 in a tMap, and write to tAdvancedOutputXML.

Regards,

Jo

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog