Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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 :
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:
Hi,
Thanks for your help... starting with your advice, i've found how to deal with it !!!
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"
]
}
]
Under Child add Attribute - say give the name as class and assign a static value of array.
Something like this -
Hi,
Thanks for your help... starting with your advice, i've found how to deal with it !!!
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"
]
}
]
Glad it could help.
Please mark the topic as resolved so that it will help our Talend community members.