cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Need to join the input array of objects to string

arunnp
New Contributor II

Hi
The json input I get to the pipeline is array of objects. I need iterate each object data and join as a string.
Also I need to append some html code in between.
Ex: input json
โ€œchathistโ€: [{
โ€œcreated_byโ€: โ€œtestโ€,
โ€œcreated_dateโ€: 1626244986151,
โ€œinformation_typeโ€: โ€œRequestโ€,
โ€œtextโ€: "Account ",
โ€œcontentโ€: โ€œโ€,
โ€œcontent_typeโ€: โ€œQuestionโ€
}, {
โ€œcreated_byโ€: โ€œWsswWโ€,
โ€œcreated_dateโ€: 1626244990226,
โ€œinformation_typeโ€: โ€œResponseโ€,
โ€œtextโ€: "Clicca sulla Societร  alla quale ",
โ€œcontentโ€: โ€œโ€,
โ€œcontent_typeโ€: โ€œtextโ€
}, {
โ€œcreated_byโ€: โ€œtestโ€,
โ€œcreated_dateโ€: 1626244998853,
โ€œinformation_typeโ€: โ€œRequestโ€,
โ€œtextโ€: โ€œexample test456โ€,
โ€œcontentโ€: โ€œโ€,
โ€œcontent_typeโ€: โ€œsrnโ€
}
]

This input array of objects need to parse and join as string. First I need to check array length > 0
I have similar logic using JSonata. I am trying to achieve this using Expression builder.

{{ $count($Request.Hist ) > 0 ?
$join( [ โ€œ[code]

[code]

โ€ & $Header & โ€œ


โ€,
$join($Request.ChatHist.($.content_type != โ€œsrnโ€ ? ($.created_by=โ€œabcโ€ ? โ€œ[code]โ€ & โ€œVA: " &โ€" : "[code] โ€ฆ

Can we use JSonata in Snaplogicโ€ฆ ? if not how we can achieve this through expression builder. I tried few ways using Array and String function but did not resolve.
Pls suggest.
thanks
arun

10 REPLIES 10

arunnp
New Contributor II

@j.angelevski Thanks fo the solution.
I used your approach to implement the logic to loop through complete input array to read data and to create a formatted text message.
regds
arun