Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
iztoogood
Contributor III
Contributor III

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 :

0683p000009M0RA.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:

0683p000009M0Mf.png

 

 

Labels (3)
1 Solution

Accepted Solutions
iztoogood
Contributor III
Contributor III
Author

Hi,

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

0683p000009M0RP.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

3 Replies
iamabhishek
Creator III
Creator III

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

Something like this - 

0683p000009M0RK.jpg

iztoogood
Contributor III
Contributor III
Author

Hi,

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

0683p000009M0RP.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"
		]
	}
]
iamabhishek
Creator III
Creator III

Glad it could help.

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