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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
AGadiyar
Contributor
Contributor

Array with single element is not getting populated within [] in Talend using MongoDB output

Hi Team,

I am trying to insert a JSON document with arrays into the target mongoDB and the issue I am facing is array with one element is not getting enclosed within square brackets whereas array with more than one element is working fine.

Single element:

"project" : {

          "projectName" : "AAU",

          "delay" : "0 days",

          "projectBudget" : "315000000"

        }

Multiple elements:

"project" : [ 

            {

              "projectName" : "AAD",

              "delay" : "3 days",

              "projectBudget" : "90000000"

            }, 

            {

              "projectName" : "AAE",

              "delay" : "3 days",

              "projectBudget" : "105000000"

            }

          ]

Output expected: Even for single element output to come within square brackets [ ]

"project" :[ {

          "projectName" : "AAU",

          "delay" : "0 days",

          "projectBudget" : "315000000"

        }

]

Any help on this is much appreciated.

Thanks!

Labels (3)
3 Replies
gjeremy1617088143

Hi, does the json are created with talend or does they come from an other source ?

Project is just a part of tje json or it's the root element ?

 

Send me Love and Kudos

AGadiyar
Contributor
Contributor
Author

JSON is created within Talend..we are using mongodb input, reading the data from a collection and trying to convert to the required json structure within talend. Project is part of a json. Attaching the screenshot for reference0695b00000GhORLAA3.png

gjeremy1617088143

Hi, @AGadivar, if projects array is the last thing on your json it could be esay to rewrite data :

you read your json as a string then you could do something like that :

((your string).replaceAll(""project\\" \\: \\{",'"project" : [ 

            {').replaceAll("(?<!        \\}

)\\]$","        }

]")

Send me Love and Kudos