how to ? : json array as well if single entry

Highlighted
Six Stars

how to ? : json array as well if single entry

Hello,

I'm trying to build a json with an array element,

when the field has multiple element : the json element is ok, it's an array as wanted...

but if the fied has a single entry... the element is turned as string and i would like it to stay a array with a single entry.

My exampel job look like that :

fatherAndChild.png

its résult is :

.-------+-----------------.
|       show source       |
|=------+----------------=|
|Father |Child            |
|=------+----------------=|
|Pierre |Kevin,Jordy,Dylan|
|Paul   |Lorie,Alizé      |
|Jacques|Lana             |
'-------+-----------------'

.-------+-----.
|Child as row |
|=------+----=|
|Father |Child|
|=------+----=|
|Pierre |Kevin|
|Pierre |Jordy|
|Pierre |Dylan|
|Paul   |Lorie|
|Paul   |Alizé|
|Jacques|Lana |
'-------+-----'
.-----------------------------------------------------.
|                  children in array                  |
|=---------------------------------------------------=|
|json                                                 |
|=---------------------------------------------------=|
|{"Father":"Pierre","Child":["Kevin","Jordy","Dylan"]}|
|{"Father":"Paul","Child":["Lorie","Alizé"]}          |
|{"Father":"Jacques","Child":"Lana"}                  |
'-----------------------------------------------------'

.---------------------------------------------------------------------------------------------------------------------------------------.
|                                                                result                                                                 |
|=-------------------------------------------------------------------------------------------------------------------------------------=|
|json                                                                                                                                   |
|=-------------------------------------------------------------------------------------------------------------------------------------=|
|[{"Father":"Pierre","Child":["Kevin","Jordy","Dylan"]},{"Father":"Paul","Child":["Lorie","Alizé"]},{"Father":"Jacques","Child":"Lana"}]|
'---------------------------------------------------------------------------------------------------------------------------------------'

the json out is :

[
	{
		"Father": "Pierre",
		"Child": [
			"Kevin",
			"Jordy",
			"Dylan"
		]
	},
	{
		"Father": "Paul",
		"Child": [
			"Lorie",
			"Alizé"
		]
	},
	{
		"Father": "Jacques",
		"Child": "Lana"
	}
]

 Lana is my problem ... i would like it to look like ["Lana"]

 

here is how i'have set the TWriteJSONFlied:

tWriteJSONField.png

 

 

Tags (1)

Accepted Solutions
Six Stars

Re: how to ? : json array as well if single entry

Hi,

Thanks for your help... starting with your advice, i've found how to deal with it !!!

2018_10_11_13_57_56_tWriteJSONField_1.png

it gives exactly what i need :

.-----------------------------------------------------.
|                  children in array                  |
|=---------------------------------------------------=|
|json                                                 |
|=---------------------------------------------------=|
|{"Father":"Pierre","Child":["Kevin","Jordy","Dylan"]}|
|{"Father":"Paul","Child":["Lorie","Alizé"]}          |
|{"Father":"Jacques","Child":["Lana"]}                |
'-----------------------------------------------------'
[
	{
		"Father": "Pierre",
		"Child": [
			"Kevin",
			"Jordy",
			"Dylan"
		]
	},
	{
		"Father": "Paul",
		"Child": [
			"Lorie",
			"Alizé"
		]
	},
	{
		"Father": "Jacques",
		"Child": [
			"Lana"
		]
	}
]

View solution in original post


All Replies
Nine Stars

Re: how to ? : json array as well if single entry

Under Child add Attribute - say give the name as class and assign a static value of array.

Something like this - 

tWriteJSONFields-1.JPG

Six Stars

Re: how to ? : json array as well if single entry

Hi,

Thanks for your help... starting with your advice, i've found how to deal with it !!!

2018_10_11_13_57_56_tWriteJSONField_1.png

it gives exactly what i need :

.-----------------------------------------------------.
|                  children in array                  |
|=---------------------------------------------------=|
|json                                                 |
|=---------------------------------------------------=|
|{"Father":"Pierre","Child":["Kevin","Jordy","Dylan"]}|
|{"Father":"Paul","Child":["Lorie","Alizé"]}          |
|{"Father":"Jacques","Child":["Lana"]}                |
'-----------------------------------------------------'
[
	{
		"Father": "Pierre",
		"Child": [
			"Kevin",
			"Jordy",
			"Dylan"
		]
	},
	{
		"Father": "Paul",
		"Child": [
			"Lorie",
			"Alizé"
		]
	},
	{
		"Father": "Jacques",
		"Child": [
			"Lana"
		]
	}
]

View solution in original post

Nine Stars

Re: how to ? : json array as well if single entry

Glad it could help.

Please mark the topic as resolved so that it will help our Talend community members.

2019 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog