Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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

Labels (4)
1 Reply
Anonymous
Not applicable
Author

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.


json2xml_Order2PO_Transform9.zip