Forum Discussion
Hi Brian,
Below screen shot you are trying to achieve?
Sorry should have provided the structure too
More like this:
[
[
{
“newRows”: [
{
“rowNumber”: 1,
“ORG_VALUE_SRC”: “1400076”,
“ORG_VALUE_TGT”: “1400076GBP”,
“CREATE_DATE”: “2018-02-28”,
“UPDATE_DATE”: “2018-02-28”
},
{
“rowNumber”: 2,
“ORG_VALUE_SRC”: “1400076”,
“ORG_VALUE_TGT”: “1400076EUR”,
“CREATE_DATE”: “2018-02-28”,
“UPDATE_DATE”: “2018-02-28”
},
{
“rowNumber”: 3,
“ORG_VALUE_SRC”: “1400077”,
“ORG_VALUE_TGT”: “1400077GBP”,
“CREATE_DATE”: “2018-02-28”,
“UPDATE_DATE”: “2018-02-28”
}
]
}
]
]
Basically a row for every source row using the “Title” as the key and “Value” from “myRows.cells” as the value. My need is grander than this but figured if someone could steer me in the right direction we could take it from there.
Thanks
- bojanvelevski4 years agoValued Contributor
Hey @darshthakkar,
I suppose you can remove the curly brackets from your final string, but if you want to go and make this solution totally dynamic, than I suggest to remove the brackets on an object level with the following expression:
$group.map(x=>x.toString().substring(1,x.toString().length-1)).toString()
What we’re doing here is first we’re mapping/iterating through the array and turning every object in it into a string:
[{ "name": "John", "age": 33 }, { "name": "Jack", "age": 23 }, { "name": "Jill", "age": 43 }]
will become:
[ "{name=John, age=33}" "{name=Jack, age=23}" "{name=Jill, age=43}" ]
In the same iteration we’re removing the first and last character which are the object curly brackets. The rest is clear, just concatenate the strings in the array:
[ "name=John, age=33" "name=Jack, age=23" "name=Jill, age=43" ]
End result:
name=John, age=33,name=Jack, age=23,name=Jill, age=43
With this we’re excluding any possibility of removing a curly brackets which are in the values of the JSON objects and should not be excluded.
Sample:
[ { "name": "John{test}", "age": 33 }, { "name": "Jack{test}", "age": 23 }, { "name": "Jill{test}", "age": 43 } ]
Result while replacing curly brackets on final string:
name=Johntest, age=33,name=Jacktest, age=23,name=Jilltest, age=43
Result while removing curly brackets on object level with mapping:
name=John{test}, age=33,name=Jack{test}, age=23,name=Jill{test}, age=43
Regards,
Bojan - darshthakkar4 years agoValued Contributor
Thank you @bojanvelevski for the detailed solution and steps.
I was planning to use column.replace() instead of column.replaceAll() however I see your point, for removing the opening {, column.replace() would have worked seamlessly but for ending }, column.replace() might have removed the first occurrence of } instead of the actual end }.Thank you again for the explanation, really means a lot to me. I will try the above-mentioned steps and keep you posted on how it goes…
- darshthakkar4 years agoValued Contributor
@bojanvelevski: Let’s assume that I’ve to remove all the existing { }, should we be using the column.replaceAll() then?
Really appreciate your help and insights into this one.
Thanks!
Regards,
DT- bojanvelevski4 years agoValued Contributor
Yes, there’s no need for further complications, replaceAll will do the job.