Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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!
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
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 reference
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