Nitesh Kumar
Nitesh Kumar

Reputation: 885

Talend DB to JSON OutPut file

I am stuck in one job of Talend. I am using Talend for migrating the DB fields into a JSON file.

I am successfully able to do the job but the JSON format which I am getting is an array format, not the customized format like address fields are not coming under parent child relationship.

In my job I am reading the data from file storing it into db and then generating the JSON file.

Current JSON output:

[ 
  { 
    "name":"test", 
    "age":"21", 
    "phone":"12345678", 
    "city":"india", 
    "state":India", 
    "country":"India" 
  } 
] 

Desired JSON output:

[
  {
    "profile": { 
        "name":"test", 
        "age":"21", 
        "phone":"12345678", 
    },
    "address": { 
        "city":"india", 
        "state":"India", 
        "country":"India" 
    }
  }
] 

There are majorly two issue with my job :

enter image description here

Can any one please help me out in this.

Upvotes: 1

Views: 3443

Answers (1)

tobi6
tobi6

Reputation: 8239

tFileOutputJSON seems to be a bit inflexible when it comes to structuring the JSON output.

Lets take a tWriteJSONField component instead. In this component, you need an input schema like:

  • profile (will be empty)
  • name
  • age
  • phone
  • address (will be empty)
  • city
  • state
  • country

Now set an output column first. Select Remove root node. Then configure the JSON tree like this:

tWriteJSONField JSON Tree config page

Here is my output (I took your example data):

{
    "profile": {
        "name": "test",
        "age": "21",
        "phone": "123456789"
    },
    "address": {
        "city": "india",
        "state": "India",
        "country": "India"
    }
}

It should be possible to work from here on to get the desired output.

Upvotes: 1

Related Questions