How to transform multi level xml message to multi level JSON Output and generate a file output

Four Stars

How to transform multi level xml message to multi level JSON Output and generate a file output

I need to create a map between multi level xml input file and transform using map source xml format to json format and generate a multi level output json file as mentioned below.

 

Sample input : 

<Employees>
   <Employee>
      <ProjectDetails>
           <ProjectName>ABC</ProjectName>
           <ProjectLocation>Bangalore</ProjectLocation>
       </ProjectDetails>
       <EmployeeDetails>
           <EmpID>EXP001</EmpID>
           <EmpName>Kumar</EmpName>
       </EmployeeDetails>
   </Employee>

   <Employee>
      <ProjectDetails>
        <ProjectName>XYZ</ProjectName>
        <ProjectLocation>Bangalore</ProjectLocation>
      </ProjectDetails>
      <EmployeeDetails>
        <EmpID>EXP0012</EmpID>
        <EmpName>Shanmugam</EmpName>
      </EmployeeDetails>
   </Employee>
</Employees>

Sample JSON output expected : 
{
"employees": {
    "employee":

    [

      {
        "firstName": "John",
        "EmpID": "Doe",
        "ProjectDetails":

        {
           "ProjectName": "ABC",
           "ProjectLocation" : "Bangalore"
        }
      },
     {
        "firstName": "John",
         "EmpID": "Doe",
          "ProjectDetails":

          {
             "ProjectName": "ABC",
             "ProjectLocation" : "Bangalore"
          }
      }
    ]
  }
}

 

I am finding it difficult to generate output in target multi level JSON format as tFileOutputJSON node is generating flat JSON structure only.

 

Any suggession on steps to generate multi level JSON file is much appreciated

Four Stars

Re: How to transform multi level xml message to multi level JSON Output and generate a file output

I managed to get it working using approach mentioned below.

 

tFileInputJson --> tWriteXMLField --> tFileOutputRaw

 

Note : I am using tFileOutputRaw instead of tFileOutputXML as i am already parsing the data in tWriteJsonField.

 

Any comment of better practice to improve my solution and maping the same is much appreciated.

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

2019 GARNER 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

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Agile Data lakes & Analytics

Accelerate your data lake projects with an agile approach

Watch