Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
<p>Hi,</p>
<p>i am using tfileoutputjson to out a jsonfile written using twritejson , in tfileoutput there are two options either create an array object or name a data block . I dont want to use any of them i want the json to be splitted into different objects rather than being stored in an array.<li-image width="469" height="45" alt="problem.PNG" align="inline" id="19082i353F7878F3F8E24C" size="large" sourcetype="new"></li-image></p>
Hi,
The problem i'm facing is that the tfileoutputjson combines different objects in a particular json under a single array , I want the objects to be stored in different files .
For eg :- the output im getting is
[ {Employee: .................}, {Employee:........}]
I want the output to be
File 1 : {Employee : .........} // Details of first employee
File 2 : {Employee : .........} // Details of second employee
Can this be done using tfileoutpujson? or is there any other method to split a json array into different files in talend.
I created a test job that logs the full JSON input and each Employee JSON block parsed from the full input:
.------------------------------------------------------------------------------------------------------------------.
| #1. tLogRow_1 |
+------+-----------------------------------------------------------------------------------------------------------+
| key | value |
+------+-----------------------------------------------------------------------------------------------------------+
| json | {"Employee":{"id":1,"name":"John"},"Employee":{"id":2,"name":"Sally"},"Employee":{"id":3,"name":"James"}} |
+------+-----------------------------------------------------------------------------------------------------------+
.------------------------------------------------------.
| #1. tLogRow_2 |
+--------------+---------------------------------------+
| key | value |
+--------------+---------------------------------------+
| employeeJson | {"Employee":{"id":"1","name":"John"}} |
+--------------+---------------------------------------+
.-------------------------------------------------------.
| #2. tLogRow_2 |
+--------------+----------------------------------------+
| key | value |
+--------------+----------------------------------------+
| employeeJson | {"Employee":{"id":"2","name":"Sally"}} |
+--------------+----------------------------------------+
.-------------------------------------------------------.
| #3. tLogRow_2 |
+--------------+----------------------------------------+
| key | value |
+--------------+----------------------------------------+
| employeeJson | {"Employee":{"id":"3","name":"James"}} |
+--------------+----------------------------------------+
Here is a screenshot of the job:
Note the Xpath queries in the tExtractJSONFields component. Because "Get Nodes" is checked, you will get all of the JSON at the node as a string, which is what you want.
Here you see the output files and their contents. I used the loop index of the iteration in the file name to create separate file names:
$ pwd
c:/temp
$ ls -1 Employee*
Employee1-out.json
Employee2-out.json
Employee3-out.json
$ head Employee*
==> Employee1-out.json <==
{"Employee":{"id":"1","name":"John"}}
==> Employee2-out.json <==
{"Employee":{"id":"2","name":"Sally"}}
==> Employee3-out.json <==
{"Employee":{"id":"3","name":"James"}}
I am attaching a zip archive of the test job so you can look at the other components to see the details.
Hi,
Thank you for your help your job is running perfectly well . Can I output these different files in a column in postgresql .
Since your original question was answered, please mark this topic as solved by selecting my answer as the solution.
You can read about the Postgres component yourself and learn how to use it. Here is the Talend documentation for all of the Postgres components:
https://help.talend.com/reader/PEtNf6RuyCZnH5XfH7jFow/zb5SBsH8S3EnHv3PT_NY4w
You can also search this forum as I am sure someone has done it before.