Six Stars

Creating arrays in JSON with Talend

I was able to create this JSON strucure in Talend (with tWriteJSONField):

{
  "rootTag": {
    "authentication": {
      "token": "blablba"
    },
    "payload": {
      "update": {
        "liso": "AT",
        "dlyr": "2017",
        "delAutoModSave": "Y",
        "updateDateTime": "Y"
      }
    }
  }
}

But I don't know how to create this structure in Talend:

{
  "authentication": {
    "token": "blabla"
  },
  "payload": {
    "update": [
      {
        "liso": "AT",
        "dlyr": "2017",
        "delAutoModSave": "Y",
        "updateDateTime": "Y"
      }
    ]
  }
}

I need this to be a payload for the call to the service, How can I create the mention JSON structure with Talend?

 

2 REPLIES
Eight Stars

Re: Creating arrays in JSON with Talend

Hi,

 

1-You should flag this checkbox in tWriteJsonField component:

Capture.PNG

2-Regarding bracket issue, there is a JIRA bout it: https://jira.talendforge.org/browse/TDI-39421

 

If you have only one update line, you will get:

{
"authentication": {
"token": "blablba"
},
"payload": {
"update": {
"liso": "AT",
"dlyr": "2017",
"delAutoModSave": "Y",
"updateDateTime": "Y"
}
}
}

 

But if you have two lines, you will get:

{
"authentication": {
"token": "blablba"
},
"payload": [
{
"liso": "AT",
"dlyr": "2017",
"delAutoModSave": "Y",
"updateDateTime": "Y"
},
{
"liso": "AT",
"dlyr": "2017",
"delAutoModSave": "Y",
"updateDateTime": "Y"
}
]
}

 

3-You could use Data Mapper to get your expected structure (Even with a single update line).

 

Regards.

 

Eric

 

Six Stars

Re: Creating arrays in JSON with Talend

I need it for one line. So the only option is tHmap.

Aha I see the available options:

1) Use JSON string and tReplace to correct "wrong" node types
2) Use tXmlMap to build a DOM
3) Use tJSONDocOutput from Talend Exchange
4) Use Platform / TDM