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

bojanvelevski
Valued Contributor

Hi @arunnp,

Check if this is the correct format according to your requirement:

image

If it is, use the following expression in a mapper:

$chathist.length > 0 ? $chathist.map(x=>x.toString().replaceAll(โ€˜,โ€™,โ€˜&โ€™).replace(/{|}/gi,โ€˜โ€™)) : $chathist

arunnp
New Contributor II

Hi @bojanvelevski Thanks for reply.
I am not looking for concatenating the fields as string. The requirement is go through each object in the array appending the โ€œtextโ€ field value inside the โ€œcontentโ€ object.
Below is the sample jsonata expression for this

image

the sample array is like this
โ€œchathistโ€: [{
โ€œcreated_byโ€: โ€œTestโ€,
โ€œtextโ€: โ€œAccountโ€,
โ€œcontentโ€: โ€œโ€,
โ€œcontent_typeโ€: โ€œQuestionโ€
}, {
โ€œcreated_byโ€: โ€œTestโ€,
โ€œtextโ€: โ€œClicca sulla ttger alla wrtr rtwt lโ€™rewrre er deve ererg la :

  • <a role="button" tabindex="0" class="mccs-input">ffdgc!โ€,
    โ€œcontentโ€: โ€œโ€,
    โ€œcontent_typeโ€: โ€œtextโ€
    }, {
    โ€œcreated_byโ€: โ€œTestโ€,
    โ€œtextโ€: "Management ",
    โ€œcontentโ€: โ€œโ€,
    โ€œcontent_typeโ€: โ€œQuestionโ€
    }, {
    โ€œcreated_byโ€: โ€œTestโ€,
    โ€œtextโ€: "Quale resettare?

    • <a role="button" ",
      โ€œcontentโ€: โ€œโ€,
      โ€œcontent_typeโ€: โ€œtextโ€
      }, {
      โ€œcreated_byโ€: โ€œTestโ€,
      โ€œtextโ€: โ€œReset Xchangingโ€,
      โ€œcontentโ€: โ€œโ€,
      โ€œcontent_typeโ€: โ€œQuestionโ€
      }, {
      โ€œcreated_byโ€: โ€œTestโ€,
      โ€œcontent_typeโ€: โ€œMpsโ€,
      โ€œcontentโ€: {
      โ€œintentโ€: โ€œchangingโ€,
      โ€œvideo_URLโ€: null,
      โ€œsolution_URLโ€: โ€œโ€,
      โ€œtitleโ€: โ€œReset changingโ€,
      โ€œtextโ€: โ€œScriva una e-mail a xch-helpdesk@xchanging.it<span style="color: black;">oppure si sul desktop lโ€™icona โ€
      }
      }]
      thanks
      arun

bojanvelevski
Valued Contributor

The samples you are sending are pretty hard to understand. Send one sample object before the transformation, and one after, and use the Preformatted text option while posting JSON data.

the sample input.

"chathist": [{
		"created_by": "Test",
		"text": "Account",
		"content": "",
		"content_type": "Question"
	}, {
		"created_by": "USer1",
		"text": "Clicca sulla ttger alla wrtr rtwt l'rewrre er deve ererg la :<b><br><br><ul><li><a role=\"button\" tabindex=\"0\" class=\"mccs-input\">ffdgc!</a>",
		"content": "",
		"content_type": "text"
	}, {
		"created_by": "User1",
		"text": "Management ",
		"content": "",
		"content_type": "Question"
	}, {
		"created_by": "Test",
		"text": "Quale resettare?<b><br><br><ul><li><a role=\"button\" ",
		"content": "",
		"content_type": "text"
	}, {
		"created_by": "User1",
		"text": "Reset  Xchanging",
		"content": "",
		"content_type": "Question"
	}, {
		"created_by": "User1",
		"content_type": "Mps",
		"content": {
			"intent": "changing",
			"video_URL": null,
			"solution_URL": "",
			"title": "Reset changing",
			"text": "Scriva una e-mail a<strong> xch-helpdesk@xchanging.it</strong><span style=\"color: black;\">oppure si  sul desktop l'icona </span>"
		}
	}]

the example sample output.

VA history:
User1: IBM Demo: What is LUCA
VA: What is MNCQ Answer: MNCQ stands for dafsasf. 
User1: Marked the solution NOT helpful. Comment: needs additional detail
VA: Feedback recorded
VA: feedback to improve. view the other.
User1: window login
VA: Please click for your query. If you do not wish ask any other question.