1

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 :

  • JSON customised format
  • No of row per file

enter image description here

Can any one please help me out in this.

tobi6
  • 8,033
  • 6
  • 26
  • 41
Nitesh Kumar
  • 875
  • 4
  • 20
  • 39
  • Please post JSON code and how you want the JSON to look like. For [numbers of rows look here](http://stackoverflow.com/a/37373455/5191221), might help. – tobi6 Jun 08 '16 at 12:52
  • current output: [ { "name":"test", "age":"21", "phone":"12345678", "city":"india", "state":India", "country":"India" } ] desired output: [ { "profile": { "name":"test", "age":"21", "phone":"12345678", } "address": { "city":"india", "state":India", "country":"India" } ] – Nitesh Kumar Jun 08 '16 at 13:12

1 Answers1

1

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.

tobi6
  • 8,033
  • 6
  • 26
  • 41