Creating arrays in JSON with Talend

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?

 

Nine 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

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Downloads and Trials

Test drive Talend's enterprise products.

Downloads