
Anonymous
Not applicable
2013-09-23
02:37 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
converting XML to JSON
Hi All,
I need to covert a XML to json, I am using talend 5.0,2 version, please suggest me how can I achieve the below sample working.
Sample Input XML:
<student>
<name>john</name>
<class>8</class>
<age>12</age>
<subject>
<subject_name>Physics</subject_name>
<score>80</score>
<grade>B</grade>
<percentage>75%</percentage>
</subject>
<subject>
<subject_name>Chemistry</subject_name>
<score>85</score>
<grade>B</grade>
<percentage>82%</percentage>
</subject>
<subject>
<subject_name>Computers</subject_name>
<score>90</score>
<grade>A</grade>
<percentage>87%</percentage>
</subject>
<student>
Expected Output:
{
"student": {
"name": "john",
"class": "8",
"age": "12",
"subject":
}
}
I need to covert a XML to json, I am using talend 5.0,2 version, please suggest me how can I achieve the below sample working.
Sample Input XML:
<student>
<name>john</name>
<class>8</class>
<age>12</age>
<subject>
<subject_name>Physics</subject_name>
<score>80</score>
<grade>B</grade>
<percentage>75%</percentage>
</subject>
<subject>
<subject_name>Chemistry</subject_name>
<score>85</score>
<grade>B</grade>
<percentage>82%</percentage>
</subject>
<subject>
<subject_name>Computers</subject_name>
<score>90</score>
<grade>A</grade>
<percentage>87%</percentage>
</subject>
<student>
Expected Output:
{
"student": {
"name": "john",
"class": "8",
"age": "12",
"subject":
}
}
602 Views
3 Replies

Anonymous
Not applicable
2013-09-23
02:56 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You can use a tFileInputXML to read an XML structured file and extracts data, then link it to a tWriteJsonField to construct a json string, then, output the json string to a file with tFileOutputDelimited, the job design looks like:
tFileInputXML--main--tWriteJsonField--main-->tFileOutputDelimited
For more details, please see my screenshots and let me know if you have any questions.
Best regar
Sabrina
You can use a tFileInputXML to read an XML structured file and extracts data, then link it to a tWriteJsonField to construct a json string, then, output the json string to a file with tFileOutputDelimited, the job design looks like:
tFileInputXML--main--tWriteJsonField--main-->tFileOutputDelimited
For more details, please see my screenshots and let me know if you have any questions.
Best regar
Sabrina
602 Views

Anonymous
Not applicable
2013-09-23
06:20 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sabrina,
Thanks for your reply, it helped me.
One more clarification, I am able to make only one loop element, what if I have multiple elements to be looped.
How do we achieve that? and
can you please brief me the importance of group_id in this job.
example:
<student>
<name>john</name>
<class>8</class>
<age>12</age>
<subject>
<subject_name>Physics</subject_name>
<score>80</score>
<grade>B</grade>
<percentage>75%</percentage>
</subject>
<subject>
<subject_name>Chemistry</subject_name>
<score>85</score>
<grade>B</grade>
<percentage>82%</percentage>
</subject>
<address_details>
<address>
<address_type>Temp Address</address_type>
<address_1>main</address_1>
<address_2>India</address_2>
<address_3>Delhi</address_3>
</address>
<address>
<address_type>Permanent Address</address_type>
<address_1>main</address_1>
<address_2>USA</address_2>
<address_3>Newyork</address_3>
</address>
</address_details>
</student>
Thanks for your reply, it helped me.
One more clarification, I am able to make only one loop element, what if I have multiple elements to be looped.
How do we achieve that? and
can you please brief me the importance of group_id in this job.
example:
<student>
<name>john</name>
<class>8</class>
<age>12</age>
<subject>
<subject_name>Physics</subject_name>
<score>80</score>
<grade>B</grade>
<percentage>75%</percentage>
</subject>
<subject>
<subject_name>Chemistry</subject_name>
<score>85</score>
<grade>B</grade>
<percentage>82%</percentage>
</subject>
<address_details>
<address>
<address_type>Temp Address</address_type>
<address_1>main</address_1>
<address_2>India</address_2>
<address_3>Delhi</address_3>
</address>
<address>
<address_type>Permanent Address</address_type>
<address_1>main</address_1>
<address_2>USA</address_2>
<address_3>Newyork</address_3>
</address>
</address_details>
</student>
602 Views

Anonymous
Not applicable
2013-09-26
12:49 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Sabrina,
Thanks for your reply, it helped me.
One more clarification, I am able to make only one loop element, what if I have multiple elements to be looped.
How do we achieve that? and
can you please brief me the importance of group_id in this job.
I have replied you in your another 31847, about group_id in this job, it is set with a fixed value and will be used as a group element on tWriteJsonField so as to generate only one string output, otherwise, it will generate multiple string outputs for each incoming data without group_id.
Shong
602 Views
